java - How to round a big number (precision 19, scale 2) to whole integer? -
i want round big number nearest integer:
ex1:-26,687,872,856,567,000.32, output should be:-26,687,872,856,567,000
ex2:-26,687,872,856,567,000.51, output should be:-26,687,872,856,567,001
i using expression in jasper report:
math.round($v(cost}) and have set $v{cost}, both java.lang.float , java.lang.double, i'm not getting correct results. float displays 2147483647.
you commented:
i changed float double, still not getting expected output. think double can handle 64-bits.
there several misconceptions here. consult the manual.
float,float8,double precisionsynonyms in postgres type system. may thinking offloat4a.k.a.real, occupies 4 bytes.float8-byte quantity, "64 bits" right.floatstill for:
15 decimal digits precision
bold emphasis mine.
your attempt store number precision of 19 (19 significant decimal digits) bound fail. try:
select '-26687872856567777.77'::float::numeric; result:
-26687872856567800 as can see, number got rounded 15 significant digits.
the solution in manual, too:
if require exact storage , calculations (such monetary amounts), use
numerictype instead.
especially numbers more 15 significant digits.
i can't stress enough. use numeric. task simple:
select round('-26687872856567777.77'::numeric); result:
-26687872856567778 or cast bigint, number rounded automatically. same result, different data type:
select '-26687872856567777.77'::numeric::bigint;
Comments
Post a Comment