• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rounding up of values..  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello world,
When I use the Float.parseFloat(String s) method it rounds up the value. For example 35.444 is rounded up to 35.45. For my requirements, I don't wont this to happen. Could you please tell me how to stop this rounding up values.
Thank you very much....
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Float.parseFloat("35.444") works as expected on my machine.

However, you can use BigDecimal from java.math package to get more precision control.
BigDecimal b1 = new BigDecimal (String.valueOf(35.444));
System.out.println(b1); // prints 35.444
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!