• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Formatting Number as percentage using <fmt:FormatNumber>

 
Greenhorn
Posts: 27
Eclipse IDE Oracle Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Divide the value by 100.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
I got it working by divide by 100...
reply
    Bookmark Topic Watch Topic
  • New Topic