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
Re: formatting a percentage in J#
Re: formatting a percentage in J#
Re: formatting a percentage in J#
Quote:
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.