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

Formatting Number as percentage using <fmt:FormatNumber>

 
Pawan Choure
Greenhorn
Posts: 27
Eclipse IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Divide the value by 100.
 
Stefan Evans
Bartender
Posts: 1721
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Posts: 27
Eclipse IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
I got it working by divide by 100...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic