|
-
Mar 9th, 2010, 09:32 AM
#1
Thread Starter
Member
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
-
Mar 9th, 2010, 10:02 AM
#2
Re: formatting a percentage in J#
-
Mar 9th, 2010, 10:03 AM
#3
Thread Starter
Member
Re: formatting a percentage in J#
-
Mar 9th, 2010, 01:48 PM
#4
Re: formatting a percentage in J#
 Originally Posted by vbtom
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|