Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display a floating number

 
Jon Chan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I used BigDecimal instead of float to handle floating number between
db <-> object or calculation. However, there is still a problem for me to display the floating number value to user. I got a clumsy method to display a floating number:
1. use BigDecimal's toString() method.
2. spilt the string into two parts (xxxx.yyy).
3. format two parts (x,xxx.yyy).
Did anyone has another idea to solve that problem?
Thank in advance,
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you don't use java.text.NumberFormat ?
 
Jon Chan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks raimondas zemaitis!
The problem is the java's float may show a different value with the orignal one (ie 6575591.95 -> 6575592.00 ). I want a method to bypass to convert to float to show the show the value with formating (ie, ###,##0.000)
 
Jon Chan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! the simplest solution is to use "double".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic