Java - Floating point with limited decimal places but without coma -
i'm developing graphics computing application computer science course. i'm doing many calculations on vectors, i'm getting severe truncations since it's float arithmetics.
the problem tried ways of limiting decimal places of float numbers to, example, 2 places. here things tried:
1 - divide , multiply 100. not work times. never works me.
2 - use decimalformat. way of formating works if have numbers under 1000. when have numbers such 1003.3124 formats 1,003.31 . since formating returns string, parse function floats not works because of coma. tried set decimalformatsymbols() setgroupingseparator different chars, includind no space , no lenght char ( '\u0200b', '\u0000', ... ), '?' instead of desired char.
3 - set locale us. since windows running in brazillian portuguese ( here dot , coma have different papers: yours 1,300.42 ours 1.300,42! ) think stupid, it's not question here. solved nothing too.
4 - take string, remove comas , return float number. i'm doing , it's working correctly. however, since it's graphics application, i'm doing normalizations times numbers. string solution heavy.
so know of way of solving issue? need optmized one. sorry if wasn't clear.
i suggest use float
calculate , if want display numbers 2 digits after dot/coma use string.format
.
trying in ram optimize calculations not idea, floats primitive type extremely optimized java , hardware.
Comments
Post a Comment