Results 1 to 4 of 4

Thread: Need Help ASAP

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432

    Need Help ASAP

    ok i need to convert a float to a String and how do i formatt for currency????

  2. #2
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    float to a string:
    PHP Code:
    float a;
    String f;
    String.valueOf(a);
        
    // or but I am bot sure:
    a.toString(); 

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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
       }
    }

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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);
       }
    }

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