Reputation: 137
I am having 156 amounts and when I am summing up to get the total amount the amount format is like 323E43.32
which I dont want but I want it in 344234.45 format. I got the individual amount in string and before performing any operation I have typcasted it to double value.
Is there a way to format a amount from 323E43.32
to 344234.45
in java?
Code Snippet:
for (int i = 0; i < numrows; i++)
{
double temp=Double.parseDouble(orders.getString("AMOUNT"));
totalAmount=totalAmount+temp;
bean.setTotalAmount(totalAmount);
}
Upvotes: 0
Views: 487
Reputation: 7357
May this thread solve your problem?
Java division for double and float without E
with this code:
System.out.println(new DecimalFormat("#.#####").format(doubleValue));
Upvotes: 1
Reputation: 16355
Why dont you take a look at DecimalFormat
DecimalFormat formatter = new DecimalFormat("0.0000");
Double price2 = Double.parseDouble(decim.format(price));
System.out.println(price2); // it will print it in the default format
If you want to print the formatted representation, print using the format:
String s = formatter.format(price);
System.out.println("s is '"+s+"'");
Also take a look at How to format decimal numbers?
Upvotes: 2