How to Display Numbers with a specific format (Android Eclipse, Java) -


this question has answer here:

double pv = 154055.054847215 

how can display 1,540,055.055 ?

add instance of decimalformat top of method:

decimalformat 3 = new decimalformat("#,##0.000"); // display numbers separated commas every 3 digits left of decimal, , round 3 decimal places. no more, no less.  // 3 zeros after decimal point above specify how many decimal places accurate to. // 0 left of decimal place above makes numbers start "0." display "0." vs "." if don't want "0.", replace 0 left of decimal point "#" 

then, call instance "three" , pass double value when displaying:

double pv = 154055.054847215; display.settext(three.format(pv)); // displays 1,540,055.055 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -