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


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

Re: How to use decimal format.

Newsgroups comp.lang.java.help
Date 2020-11-18 17:35 -0800
References (6 earlier) <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>
Message-ID <6a63a12f-8f4d-46a8-ae6f-443cfa1bbb84n@googlegroups.com> (permalink)
Subject Re: How to use decimal format.
From Little Ninja <majdfaqir2010@gmail.com>

Show all headers | 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