groovy - JsonSlurper avoid trimming last zero in a string -
i using jsonslurper in groovy convert json text map.
def slurper = new jsonslurper(); def parsedinput = slurper.parsetext("{amount=10.00}");
result is
[amount:10.0]
i need result without trimming last zero. like
[amount:10.00]
have checked various solutions not getting converted without trimming last zero. missing here.
one of ways have found give input as:
{amount="10.00"}
in numbers , maths, 10.00
is 10.0
they same number.
they have different string representations.
if need display 10.0
user 10.00
conversion thing, need convert string 2 decimal places
something like:
def stringrepresentation = string.format("%.02f", 10.0)
but calculations, 10.0
, 10.00
same thing
edit -- try again...
right when have json:
{"amount"=10.00}
the value on right floating point number.
to keep 0 (which dropped every sane representation of numbers), need convert string.
to this, can use string.format
above (other methods available).
you cannot keep floating point number zero.
numbers don't work in every language can think of... might in cobol of memory, that's way off track
Comments
Post a Comment