java - Properly scaling BigDecimal -


i have situation want scale values in situations i'm getting exception indicates rounding required.

lets have numbers -9.999999 , 9.999999

lets care precision 4 points after decimal place. how can scale both of these numbers without checking if value positive or negative?

if example, use roundingmode.floor, get:

9.999999 scales 99999 -9.999999 scales -100000 

what 9.9999 , -9.9999, respectively.

do need check sign here? feel i'm missing something.

roundingmode.down rounds toward zero, should you're looking for. is, never increment final digit when rounds. it's equivalent truncating value @ specified scale.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -