Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #4340

Re: How to use decimal format.

X-Received by 2002:a37:b701:: with SMTP id h1mr8476673qkf.147.1605749756954; Wed, 18 Nov 2020 17:35:56 -0800 (PST)
X-Received by 2002:aca:d405:: with SMTP id l5mr1394376oig.17.1605749756673; Wed, 18 Nov 2020 17:35:56 -0800 (PST)
Path csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.help
Date Wed, 18 Nov 2020 17:35:56 -0800 (PST)
In-Reply-To <38FBCD85.87595696@crl.tel.co.jp>#1/1>
Complaints-To groups-abuse@google.com
Injection-Info google-groups.googlegroups.com; posting-host=2607:9880:2c88:1e2:554f:94cf:812e:b8f2; posting-account=fr2k9goAAACrXq1thZ00X9Z2MJ4a6mpe
NNTP-Posting-Host 2607:9880:2c88:1e2:554f:94cf:812e:b8f2
References <38F53EDC.6A96EA9A@crl.tel.co.jp> <2df6d508.a6c480a2@usw-ex0103-086.remarq.com> <38F5ACF7.1403B17E@crl.tel.co.jp> <8d4vkc$2k1$1@news.tis-in.trb> <38f8633f.822965@news.tijd.com> <38FA89F2.FE3BC702@crl.tel.co.jp> <38faac2b.6120490@news.tijd.com> <38FB09AB.28674709@crl.tel.co.jp> <38FB1304.3048CD9A@acm.org> <38fb647c.2505558@news.tijd.com> <38FBCD85.87595696@crl.tel.co.jp>#1/1>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <6a63a12f-8f4d-46a8-ae6f-443cfa1bbb84n@googlegroups.com> (permalink)
Subject Re: How to use decimal format.
From Little Ninja <majdfaqir2010@gmail.com>
Injection-Date Thu, 19 Nov 2020 01:35:56 +0000
Content-Type text/plain; charset="UTF-8"
Lines 68
Xref csiph.com comp.lang.java.help:4340

Show key headers only | View raw


On Tuesday, 18 April 2000 at 03:00:00 UTC-4, Yun Mo wrote:
> With the format "##0.##E00" and method of myformat, I got:
> a=0.01 formatted=+1E-03
> a=-100600.0 formatted=-100.6E+03
> a=-100500.0 formatted=-100.5E+03
> a=-100510.0 formatted=-100.51E+03
> a=-100500.0000000001 formatted=-100.5E+03
> a=0.0 formatted= 0E+00
> a=-1230.0 formatted=-1.23E+03
> a=99999.99951 formatted=+1E+03
> b=100000 formatted=+1E+03
> With "0.00E00" and the method of myformat, I obtained:
> a=0.01 formatted=+1.00E-02
> a=-100600.0 formatted=-1.01E+05
> a=-100500.0 formatted=-1.00E+05 (x)
> a=-100510.0 formatted=-1.01E+05 (ok)
> a=-100500.0000000001 formatted=-1.01E+05 (ok)
> a=0.0 formatted= 0.00E+00
> a=-1230.0 formatted=-1.23E+03
> a=99999.99951 formatted=+1.00E+05
> b=100000 formatted=+1.00E+05
> 
> It seems that no problem for the fixed decimal format like "0.00E00".
> Of course, there exists a worry about formatting 100500 with "0.00E00".
> In engineering, we only want some number of valid digits.
> The following format is a despoit result. The reason may be that it
> takes digit from right side of 100,000.
> At lease, the maximum integer digits should larger than 6.
> I dont't know the exact reason that it could get the expected result with "0.00E00".
> But it can guess that it takes digits from left side of 100,00 for "0.00E00".
> > java.text.DecimalFormat df =
> > (java.text.DecimalFormat)java.text.NumberFormat.getInstance();
> > df.setMaximumIntegerDigits(3);
> > System.out.println(df.format(99999.99951));//should at least throw an
> //exception, gives 000
> Dirk Bosmans wrote:
> > And don't use java.text.DecimalFormat with exponent notations. Try this one:
> >
> > java.text.DecimalFormat df = new java.text.DecimalFormat("##0.###E0");
> > System.out.println(df.format(99999.99951));//should be 100E3, gives 1E3
> >
> > Dangerous. And what about fixed point? Do you like loosing most-significand
> > digits without a warning?
> >
> > java.text.DecimalFormat df =
> > (java.text.DecimalFormat)java.text.NumberFormat.getInstance();
> > df.setMaximumIntegerDigits(3);
> > System.out.println(df.format(99999.99951));//should at least throw an
> > //exception, gives 000
> >
> > I'm reacting to following parts of Patricia Shanahan <pa...@acm.org>'s article in
> > comp.lang.java.help on 17 Apr 2000 09:31:08 EDT6
> >
> > ....
> > . If numbers that happen to be exactly representable in decimal are
> > . particularly important in your program use BigDecimal instead of double.
> > . Even if double is right for your general arithmetic, if you want a
> > . different rounding mode from round half even convert to BigDecimal
> > . before display, use BigDecimal to do the formatting.
> > .
> > . Patricia
> >
> > Greetings,
> > Dirk Bosmans
> >
> > http://users.belgacombusiness.net/arci/
> > - Applicet Framework: turns Applets into Applications
> > - ArciMath BigDecimal: now with BigDecimalFormat
u a bot and a loser

Back to comp.lang.java.help | Previous | Next | Find similar


Thread

Re: How to use decimal format. Little Ninja <majdfaqir2010@gmail.com> - 2020-11-18 17:35 -0800

csiph-web