Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating double according to "." in java [duplicate]

Tags:

java

split

double

i have a double number which is "547.123456"

i just want to use this double as "547.1" like only 1 number after "."

How can i do that?

like image 787
serkan Avatar asked May 07 '26 12:05

serkan


1 Answers

Use BigDecimal

double f=547.123456;
BigDecimal d=new BigDecimal(f);
System.out.print( d.setScale(1, RoundingMode.FLOOR));
like image 125
Nambi Avatar answered May 10 '26 02:05

Nambi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!