# juce::String(floatValue) changes

**URL:** <https://forum.juce.com/t/juce-string-floatvalue-changes/31973>\
**Category:** General JUCE discussion\
**Created:** [February 25, 2019, 3:56pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973 "2019-02-25T15:56:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakob-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jakob-2/32/783_2.png) [@jakob-2](https://forum.juce.com/u/jakob-2)\
**Post date:** [February 25, 2019, 3:56pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/1 "2019-02-25T15:56:46Z")

</div>

Hi JUCE team, in the past, `juce::String(0.5)` was turned into the string `0.50000000000000000000`. You’ve then changed it to say `0.5` instead.

It took us 3 or 4 hours to adjust automatic tests and some UI code, but that’s fine.

Then with another update you changed it back to `0.50000000000000000000`, which added work just again.

Now you’ve changed it to `5e-1` with JUCE 5.4.3. Uh, work again to keep up with changing implementations.

Without questioning your reasons, could you at least add such changes to the “BREAKING-CHANGES.txt” doc?

Also - resolution has suffered. Before, we got `0.10000000149011611938` when we converted a value tree float value to XML, and that has now turned into a less precise `1.000000014901161e-1`.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 27, 2019, 12:04pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/2 "2019-02-27T12:04:52Z")

</div>

`String (0.5)` produces “0.5”. The only way of getting “5e-1” is to opt into scientific format with the new arguments to the constructor.

The latest change uses scientific format when creating XML and JSON files. This allows us to avoid long strings like “0.50000000000000000000” bloating file sizes, whilst retaining full precision. “0.10000000149011611938” may look more precise than “1.000000014901161e-1”, but the last few significant digits there are useless. Converting between doubles and strings is surprisingly complicated, but as an approximate rule you can hold 7 significant digits in a 32 bit float and 16 significant digits in a 64 bit double. Anything beyond that is just noise and is ignored.

So yes, the string representation of XML and JSON is now different, but the information contained is unchanged - it will parse exactly the same way.

---

<div class="post-metadata">

**Author:** ![jakob-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jakob-2/32/783_2.png) [@jakob-2](https://forum.juce.com/u/jakob-2)\
**Post date:** [February 27, 2019, 12:24pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/3 "2019-02-27T12:24:38Z")

</div>

Thanks a ton for clarification! Also thanks for your explanation regarding precision - that makes perfect sense.

Great to hear that just XML and JSON are affected with the latest change… it only took 30min this time to adjust our tests. But indeed we appreciate your reasonable change.

Just adding it to your “BREAKING-CHANGES.txt” file would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![pflugshaupt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pflugshaupt/32/13206_2.png) [@pflugshaupt](https://forum.juce.com/u/pflugshaupt)\
**Post date:** [February 27, 2019, 1:53pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/4 "2019-02-27T13:53:28Z")

</div>

Although I was the one who complained about the wasted space with the older code, I now see lots of numbers like 5e-1 in .jucer file (xml) commits. IMHO the xml fixes took the whole scientific notation thing a bit too far. I especially find it weird to see font sizes like 1.3e1. In my opinion the scientific notation should only be used for quite small and very large values, otherwise things get hard to read and stuff like 1.3e1 is also a waste of space when it could just be 13.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [February 27, 2019, 2:25pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/5 "2019-02-27T14:25:19Z")

</div>

I have to agree with this a bit. One of the reasons we make our edit files raw XML is so we (and users) can open them up and read them. It’s a big cognitive load to convert from scientific notation.

Is it _possible_ to have XML as trailing-zero-trimmed standard notation? Or is that something just not allowed by the current string conversion functions?  
If so, perhaps a separate step to trim trailing zeros could be used (even if we do this manually)?

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 27, 2019, 2:40pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/6 "2019-02-27T14:40:41Z")

</div>

It’s possible, but what would you do with 1e-50?

I think picking cutoff values is the best way forward. I just need to have a think about what they should be.

---

<div class="post-metadata">

**Author:** ![bwall](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bwall/32/618_2.png) [@bwall](https://forum.juce.com/u/bwall)\
**Post date:** [February 27, 2019, 3:48pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/7 "2019-02-27T15:48:54Z")

</div>

At the moment, XML is turning 44100.0 into 4.41e4, which is tedious. So I think we should choose a cutoff that allows common values to be seen in their most natural readable format - 44100.0.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 27, 2019, 6:21pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/8 "2019-02-27T18:21:04Z")

</div>

> <https://github.com/WeAreROLI/JUCE/commit/bbe49f6b368a222997edae7b04063ca8e6e9220b>

(Sorry Jakob)

---

<div class="post-metadata">

**Author:** ![jakob-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jakob-2/32/783_2.png) [@jakob-2](https://forum.juce.com/u/jakob-2)\
**Post date:** [February 27, 2019, 8:23pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/9 "2019-02-27T20:23:50Z")

</div>

Ah that’s great, I appreciate your commit a lot.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [March 21, 2019, 5:00pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/10 "2019-03-21T17:00:51Z")

</div>

Hello-

We’ve noticed that this recent change is perhaps too enthusiastic about stripping decimal places when converting to JSON. Any double value that is a whole number is written to JSON as an integer. In other words, if we had a value of, say 20.0, we used to get:

“foo” : 20.0

and now we get:

“foo” : 20

Then when we read the JSON data back in, it’s read as an integer and not as a double, which causes issues with our schema validator.

Would you be open to changing it so that there’s always at least one decimal place written for double values?

Thanks-

Matt

---

<div class="post-metadata">

**Author:** ![pflugshaupt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pflugshaupt/32/13206_2.png) [@pflugshaupt](https://forum.juce.com/u/pflugshaupt)\
**Post date:** [March 21, 2019, 5:04pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/11 "2019-03-21T17:04:49Z")

</div>

I’d like that as well as I’m using the number format to determine types when creating ValueTrees from xml to avoid repeated conversions later. Now for whole numbers the xml looks the same for integers and doubles.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [March 21, 2019, 5:06pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/12 "2019-03-21T17:06:17Z")

</div>

OK, I’ll add that back in.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [March 21, 2019, 5:55pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/13 "2019-03-21T17:55:45Z")

</div>

Thanks very much!

Matt

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [March 21, 2019, 6:07pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/14 "2019-03-21T18:07:33Z")

</div>

Please give this a go.

> <https://github.com/WeAreROLI/JUCE/commit/0d019acd1cf6e8d28c9c19ff7e1e9a11b179527f>

If all’s well then I’ll cherry pick it over to the master branch.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [March 21, 2019, 6:56pm UTC](https://forum.juce.com/t/juce-string-floatvalue-changes/31973/15 "2019-03-21T18:56:33Z")

</div>

That works great; much appreciated. Thanks for taking care of it so quickly.

Matt
