Article View: borland.public.jbuilder.java.api
Article #2762Re: Formatting floats
From: John P. McGrath
Date: Sun, 05 Mar 2000 00:00
Date: Sun, 05 Mar 2000 00:00
22 lines
1135 bytes
1135 bytes
On Sat, 4 Mar 2000 01:26:00 -0000, Akber Datoo wrote:
> I need to format floats to be represented in a specified
> number of significant figures
Try:
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits( 1 );
nf.setMaximumFractionDigits( 2 );
System.out.println( nf.format( aNumber ) );
Number format is localized, so a number that formats as "12,345,678.99"
in a US locale will format as "12.345.678,99" in some other locales.
The NumberFormat object can be re-used, so in many cases, you will want
to create a single class (static) instance of NumberFormat.
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.132a46d8a289268f9897d8@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<89po1m$qu04@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,88f18f0a95ed80e3 X-Google-Attributes: gid1089d0,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: Formatting floats Date: 2000/03/05 Message-ID: <MPG.132a46d8a289268f9897d8@forums.borland.com> X-Deja-AN: 593338228 References: <89po1m$qu04@bornews.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.api