posted 20 years ago
That's what I get for quickly throwing up an answer w/out double-checking with the documentation. My bad: there is no "trunc()" method.
If you want to truncate a "double" value there are a couple of options:
This gives you the output:
DD1: 1234.5678
II1: 1234
DD2: 1234.0
DD2: 1234.56
So you can truncate and store the result as an "int" (such as "ii1"), or store the result as a double (such as "dd2"). Or you can truncate to two digits (such as in "dd3").
Because of the way in which real numbers are stored, you might truncate and instead of coming out with "1234.56" as here, you could get "1234.55999999999999". If you want to ensure you what gets printed out only has a certain number of digits, use the "java.text.DecimalFormat" class to do your formatting.
[ November 10, 2003: Message edited by: Wayne L Johnson ]