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();
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 } }
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 } }
Java CodeBank Entries >> Parsing URL's| Collections/ShuffleElements | Threads isAlive() | Daemon Threads |Remote Class Loading | Sorted Keys (Map) | Backwards List | Thread States | Collections/Arrays Generics | Regular Expression(Grouping and Capturing) | Properties | JLabel/JTextField Combo | Reading Request Parameter Values | Host Lookup | Setting the size of a JFrames inner-region | GUI Native L&F
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); } }
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); } }
Forum Rules