Converting a number to text/money format

Hi there,
Does anyone knows of a library or class that can convert float number to its text form?
I need it to print the quantity as the text and number.
If it is possible something that suport spanish and "pesos".

Comments

  • : Hi there,
    : Does anyone knows of a library or class that can convert float
    : number to its text form?
    : I need it to print the quantity as the text and number.
    : If it is possible something that suport spanish and "pesos".
    :
    Depending on the version of your java there are 2 possibilities:

    Java 1.5 and later: Floats are automatically changed to strings, when added to a string:
    [code]
    float f = 4;
    String s = "2 * 2 = "+f;
    System.out.println(s);
    [/code]

    Java 1.4 and earlier: Use the String.valueOf() method:
    [code]
    float f = 4;
    String s = "2 * 2 = "+String.valueOf(f);
    System.out.println(s);
    [/code]

    In Java 1.5 and later it is possible to have more control over how the number is displayed. For this you can use either the String.format() method or the Formatter class. See JavaDoc for a more detailed explanation.
  • : Java 1.5 and later: Floats are automatically changed to strings,
    : when added to a string:
    : [code]:
    : float f = 4;
    : String s = "2 * 2 = "+f;
    : System.out.println(s);
    : [/code]:
    :
    : Java 1.4 and earlier: Use the String.valueOf() method:
    : [code]:
    : float f = 4;
    : String s = "2 * 2 = "+String.valueOf(f);
    : System.out.println(s);
    : [/code]:
    :
    : In Java 1.5 and later it is possible to have more control over how
    : the number is displayed. For this you can use either the
    : String.format() method or the Formatter class. See JavaDoc for a
    : more detailed explanation.

    the String.format() method only convert the number to char and print it in certin way... I'll make use of that too...

    But what I want is a class or lib such that given a number, lets say 34.95 it returns "tirty four box(es?) 95c" or in spanish "treinta y cuatro pesos 95c"
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories