Ozuf Ozuf - 3 months ago 10
Java Question

How convert the last two zeroes of a number to decimal numbers

int numb = 200000;
DecimalFormat def = new DecimalFormat("#.00");
String finalnumb = def.format(numb);


The value of
finalnumb
is 200000.00 but I want it to be 2000.00.

Please how can I achieve this?

Answer

Oney way would be dividing numb by 100.0 (double value)

public static void main(String[] linesInFile) {
int numb = 200000;
DecimalFormat def = new DecimalFormat("#.00");
String finalnumb = def.format(numb / 100.0);
System.out.println(finalnumb);
}