truncate decimals after 2 places for double without decimal Format
I am trying to "truncate" a double to return only two decimals places.
Example:
given 1375568.13124765 would return => 1375568.13
Using Decimal format is too slow. I am calling this multiple times in a
loop. To speed up the process I am trying:
public static double castRoundTo2(double d)
{
return (long) (d * 100 + 0.5) / 100.0;
}
This is returning something like 1375568.13000015
Is there any was to cut off anything after two decimal places?
No comments:
Post a Comment