wood burning stoves 2.0*
The moose likes JSP and the fly likes Formatting Number as percentage using <fmt:FormatNumber> 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 » JSP
Bookmark "Formatting Number as percentage using <fmt:FormatNumber> " Watch "Formatting Number as percentage using <fmt:FormatNumber> " New topic
Author

Formatting Number as percentage using <fmt:FormatNumber>

Pawan Choure
Greenhorn

Joined: May 11, 2008
Posts: 27

Hi,
I want to format a number as given below

Number 5.75
Expected output:5.75%



Output is 575%
which is wrong since the expected output is 5.75%

I can achieve the expected output using


but i dont want to use that. I want to use either percent or pattern to get the desired result.

Thanks in advance......




but when i am changing


Pawan Choure
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Divide the value by 100.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
>Number 5.75
>Expected output:5.75%
>Output is 575%
>which is wrong since the expected output is 5.75%

Maybe your expected output, but the java.text.DecimalFormat class specifies that the % sign should: Multiply by 100 and show as percentage.

It is designed for the case where you do the calculation. eg 8/10 on the test translates as 80%, not 0.8%
Pawan Choure
Greenhorn

Joined: May 11, 2008
Posts: 27

Thanks for your reply.
I got it working by divide by 100...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting Number as percentage using <fmt:FormatNumber>
 
Similar Threads
Currency formatting and color
Rounding a value in jsp by using JSTL Expressions
jstl table problem
Formatting date in JSP
confused in converter