wood burning stoves 2.0*
The moose likes Java in General and the fly likes 'Implied Decimal' format in Java for Double/Float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " Watch " New topic
Author

'Implied Decimal' format in Java for Double/Float

Haq Yunus
Ranch Hand

Joined: Apr 08, 2009
Posts: 42
Hello,

I have a very simple question.

I want to know that if there is a format class, method or any wy to format a decimal number into a implied decimal format?

Some examples, for implied decimal to 2 places:

input: 12345.06
output: 1234506

input: 12345.00
output: 1234500

input: -152345.45
output: -15234545

input: -152345.457892
output: -15234546

input: 12.16223
output: 1216



I can handle the rounding, alignment, the negative sign and fixed length for the number but not this implied decimal thingy. I have looked at DecimalFormat but I couldn't find anything that does this. Also, nothing in String.format. Currently I am using a sort of a workaround that I first convert the decimal number into a String of my desired format (precision, size, padding etc.) and then through String manipulation create an implied decimal string. Am I missing something basic here?

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
[campbell@campbell1110 java]$ java DecimalDemo 123.456789
Your value is 123.456789, multiplied by 100 you get 12346 and as an int 12346
Haq Yunus
Ranch Hand

Joined: Apr 08, 2009
Posts: 42
Thanks for the idea. But you think there is no support from the formatting perspective in shape of class, method, pattern or API?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
That is formatting support. It is particularly unusual to need to round a number and multiply by 100 simultaneously, and you can't expect a standard library to provide that function.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3001
    
    9
Yeah, I've never heard of "implied decimal" before now - I doubt there's any need for a standard library. Especially when it's really, really easy to do it yourself:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'Implied Decimal' format in Java for Double/Float
 
Similar Threads
ASCII TO EBCDIC conversion preserving COMP-3
Decimals not converting to correct fractions
Localized Currency formatting issue
printf formating
Please help with a simple GUI.