java - Fomat Double to 2 Decimal Places WITHOUT Using a String -


i'm working on project requires me have double values @ 2 decimal place. using math, have numbers rounded correctly, except if there trailing zeros. want keep these 0's results 0.00 in particular list displayed in tableview, therefore must sortable numerically. i'd double values doubles may sort.

is there way can keep 2 decimal places without string.format?

thank in advance.

you can use decimalformat

decimalformat df = new decimalformat("#.00");  

00 = exactly 2 decimal places.

but give string can convert again double, if don't want have string-conversion check question see how can achieved using bigdecimal.

imho, if not learning pourposes decimalformat enough you. true, have use string in moment of conversion, you read , store double values , sorting correct...


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -