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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -