How can I stop D from dropping decimals in strings

Steven Schveighoffer schveiguy at gmail.com
Tue Feb 2 23:10:50 UTC 2021


On 2/2/21 5:27 PM, Tim wrote:
> Hi all,
> 
> I have to serialize an array like [0.0, 0.0, 0.0] to a Json object. 
> During this process, the serializer creates a string of the array, but 
> it creates "[0, 0, 0]", dropping the decimal. How can I stop this?

It totally depends on the library. As Adam says, 0.0 and 0 are generally 
interchangeable, but reality says they are sometimes not (I have had my 
share of issues with vibe.d Json treating 1.0 as Json.Type.float_ and 1 
as Json.Type.int_, where it doesn't allow you to get the int version as 
a float).

It would help to have a better understanding of why you need the .0 to 
appear.

-Steve


More information about the Digitalmars-d-learn mailing list