ok i need to convert a float to a String and how do i formatt for currency????
Printable View
ok i need to convert a float to a String and how do i formatt for currency????
float to a string:
PHP Code:float a;
String f;
f = String.valueOf(a);
// or but I am bot sure:
f = a.toString();
Just make the float a long value.
Code:import java.text.*;
class translate{
public static void main(String[] args){
NumberFormat numf = NumberFormat.getCurrencyInstance();
long l = 98564;
String s = numf.format(l);
System.out.println(s); // $98,564.00
}
}
If you want you can change the locale from the default to work with other currencies.
Code:
import java.util.*;
import java.text.*;
class translate{
public static void main(String[] args){
Locale.setDefault(Locale.UK);
NumberFormat numf = NumberFormat.getCurrencyInstance();
long l = 98564;
String s = numf.format(l);
System.out.println(s);
}
}