Converting a number to text/money format - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Converting a number to text/money format

AbateFariaAbateFaria Posts: 3Member
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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • AbateFariaAbateFaria Posts: 3Member
    : 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.