Results 1 to 4 of 4

Thread: formatting a percentage in J#

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    formatting a percentage in J#

    I was after some help into how to format a percentage for J#.

    The Code is -

    void show_revenue_info()
    {

    System.out.println(" Milk round revenue (£) : " + this.milk_revenue());
    System.out.println(" Farmer's revenue (£) : " + this.farmer_revenue());
    System.out.println(" Farmer's revenue as a percentage of the milk round revenue :" + this.farmers_revenue_as_percentage_milk_revenue());

    }

    The item which is needing to be formatted is called "this.farmers_revenue_as_percentage_milk_revenue"

    I am aware that i have to use new format which is ##.##

    hope you can help

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: formatting a percentage in J#

    Moved From The Codebank

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: formatting a percentage in J#

    moved from the Codebank?

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: formatting a percentage in J#

    Quote Originally Posted by vbtom View Post
    moved from the Codebank?
    You posted in the wrong section, the "Codebank" and Hack moved it here.

    I've never used J#, but I would assume it is very similar to normal Java.

    In Java you would do it like this (assuming you're formatting a decimal to a percent):

    Code:
    NumberFormat formatter = new DecimalFormat("0.00%"); 
    String s = formatter.format(0.08512); // -001235 
    System.out.println(s);
    and you would need to import

    Code:
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    If you already have a full number and want to limit the decimal places, you would still use the formatter, but instead of including the % in the formatting, simply append it to the string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width