Article View: borland.public.jbuilder.java.language
Article #15363Re: Limiting the number of decimal places...
From: Vasudevan Srinivasan
Date: Mon, 21 Jun 1999 00:00
Date: Mon, 21 Jun 1999 00:00
30 lines
1303 bytes
1303 bytes
You can use something like this:
double fix(double value) {
DecimalFormat d = new DecimalFormat();
d.setMaximumFractionDigits(2);
d.setDecimalSeparatorAlwaysShown(false);
d.setGroupingUsed(false);
return Double.valueOf(d.format(value)).doubleValue();
}
Vasu
Dan Patterson wrote:
> I am doing a calculation and want to limit the number of decimal places that
> are returned by the calculation. (e.g. I want 1.24 instead of
> 1.24234365423). Does anyone know how to do this ?
>
> Many thanks
>
> Dan
>
> Daniel E Patterson, Ph.D.
> Spider Product Manager
> Welcom
> 281.558.0514 Phone
> 281.584.7828 Fax
> www.welcom.com
> dpatterson@welcom.com
Technical Details
Message-ID:
<376E8082.B785F693@netrisk.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7kli52$5hj5@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,15b92570b266bfb4 X-Google-Attributes: gidf74b3,public From: Vasudevan Srinivasan <vasudevan@netrisk.com> Subject: Re: Limiting the number of decimal places... Date: 1999/06/21 Message-ID: <376E8082.B785F693@netrisk.com> X-Deja-AN: 492186844 Content-Transfer-Encoding: 7bit References: <7kli52$5hj5@forums.borland.com> To: Dan Patterson <dan-patterson@email.msn.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: NetRisk Inc Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language