Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Converting a number to text/money format Posted by AbateFaria on 10 Jul 2008 at 8:09 AM
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".
Report
Re: Converting a number to text/money format Posted by zibadian on 10 Jul 2008 at 9:12 AM
: 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:
  float f = 4;
  String s = "2 * 2 = "+f;
  System.out.println(s);


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


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.
Report
Re: Converting a number to text/money format Posted by AbateFaria on 10 Jul 2008 at 10:22 AM
: Java 1.5 and later: Floats are automatically changed to strings,
: when added to a string:
:
: 
:   float f = 4;
:   String s = "2 * 2 = "+f;
:   System.out.println(s);
: 
:
:
: Java 1.4 and earlier: Use the String.valueOf() method:
:
: 
:   float f = 4;
:   String s = "2 * 2 = "+String.valueOf(f);
:   System.out.println(s);
: 
:
:
: 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"



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.