# Is there a library that allows for the convenient use of doubles?

**URL:** <https://discourse.processing.org/t/is-there-a-library-that-allows-for-the-convenient-use-of-doubles/19532>\
**Category:** Beginners\
**Created:** [April 8, 2020, 7:49am UTC](https://discourse.processing.org/t/is-there-a-library-that-allows-for-the-convenient-use-of-doubles/19532 "2020-04-08T07:49:55Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![Math\_Machine](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Math\_Machine](https://discourse.processing.org/u/Math_Machine)\
**Post date:** [April 20, 2020, 12:40am UTC](https://discourse.processing.org/t/is-there-a-library-that-allows-for-the-convenient-use-of-doubles/19532/21 "2020-04-20T00:40:44Z")

</div>

Hey, I don’t know if this counts as on topic, but is there any way to convert a double to a string _and_ control the precision? Like, I need to be able to print a number to the console, but I need the number rounded so there are no more than 12 digits after the decimal point (this includes numbers listed in scientific notation). Is there any way to do that without manually changing each character in a string so that it’s rounded properly?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 20, 2020, 10:44am UTC](https://discourse.processing.org/t/is-there-a-library-that-allows-for-the-convenient-use-of-doubles/19532/22 "2020-04-20T10:44:36Z")

</div>

You might use String.format(pattern, number) like this

```auto
double n;
String s;
// Test 1
n = 22d/7d;
s = String.format("%1.12e", n);
println("\n" + n + "\n" + s + " " + s.length());
// Test 2
n = -Math.exp(100d);
s = String.format("%.12e", n);
println("\n" + n + "\n" + s + " " + s.length());

```

[Previous page](https://discourse.processing.org/t/is-there-a-library-that-allows-for-the-convenient-use-of-doubles/19532.md?page=1)
