aspose file tools
The moose likes Java in General and the fly likes Display a floating number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Display a floating number" Watch "Display a floating number" New topic

Display a floating number

Jon Chan

Joined: Sep 21, 2003
Posts: 7
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

Joined: Feb 23, 2001
Posts: 104
Why you don't use java.text.NumberFormat ?
Jon Chan

Joined: Sep 21, 2003
Posts: 7
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

Joined: Sep 21, 2003
Posts: 7
Oh! the simplest solution is to use "double".
I agree. Here's the link:
subject: Display a floating number
It's not a secret anymore!