Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > DecimalFormat

Reply
Thread Tools

DecimalFormat

 
 
Johnny
Guest
Posts: n/a
 
      10-25-2003
Hello,

What kind of mask should I use with DecimalFormat class if I would like to
get allways two digits after decimalpoint? E.g. if input is 100.1 then
result should be 100.10.

Then second questions is that people is USA are using
dot as a separator in decimal numbers. But in Northern
Europe it's comma. What is the most elegant way to
implement this point/comma localized difference when handling decimal
numbers?

Cheers,

It's snow in the ground here in Scandinavia now



 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      10-25-2003

"Johnny" <(E-Mail Removed)> wrote in message
news:3f9af98e$0$13811$(E-Mail Removed)...
> Hello,
>
> What kind of mask should I use with DecimalFormat class if I would like to
> get allways two digits after decimalpoint? E.g. if input is 100.1 then
> result should be 100.10.


DecimalFormat df = new DecimalFormat("0.00");

System.out.println(df.format(100.1)); // gives 100.10

>
> Then second questions is that people is USA are using
> dot as a separator in decimal numbers. But in Northern
> Europe it's comma.


Not in the UK it isn't

> What is the most elegant way to
> implement this point/comma localized difference when handling decimal
> numbers?


eh?
I've run the example code in java.text.DecimalFormat API, and can't see any
country that uses anything other than decimal point.

Have a look at that code anyway it should tell you what you want to know.

[IIRC a decimal point and full stop are different, but from an IT
perspective they are the same and are both the full stop. A true decimal
point ( · [alt 0183 on Windows]) hovers halfway up the line.]

--
Mike W


 
Reply With Quote
 
 
 
 
David Postill
Guest
Posts: n/a
 
      10-25-2003
In article <3f9af98e$0$13811$(E-Mail Removed)>, on Sun, 26 Oct 2003
01:30:34 +0300, "Johnny" <(E-Mail Removed)> wrote:

| Hello,
|
| What kind of mask should I use with DecimalFormat class if I would like to
| get allways two digits after decimalpoint? E.g. if input is 100.1 then
| result should be 100.10.
|
| Then second questions is that people is USA are using
| dot as a separator in decimal numbers. But in Northern
| Europe it's comma. What is the most elegant way to
| implement this point/comma localized difference when handling decimal
| numbers?

Have you read the Java Tutorial yet?

<http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html>

Answers both of your questions.

| Cheers,
|
| It's snow in the ground here in Scandinavia now

Pretty cold here too in the UK. No snow yet though

<davidp />

--
David Postill
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-26-2003
On Sun, 26 Oct 2003 01:30:34 +0300, "Johnny" <(E-Mail Removed)> wrote or
quoted :

>What kind of mask should I use with DecimalFormat class if I would like to
>get allways two digits after decimalpoint? E.g. if input is 100.1 then
>result should be 100.10.


http://mindprod.com/converter.html see double to String.

See also http://mindprod.com/jgloss/currency.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-26-2003
VisionSet wrote:
at is the most elegant way to
>>implement this point/comma localized difference when handling decimal
>>numbers?

>
>
> eh?
> I've run the example code in java.text.DecimalFormat API, and can't see any
> country that uses anything other than decimal point.


Then you were doing something wrong. Most European countries (definitely
Germany, France, Belgium and the Netherlands) use a decimal comma.

 
Reply With Quote
 
Mark Thornton
Guest
Posts: n/a
 
      10-26-2003
VisionSet wrote:
> "Johnny" <(E-Mail Removed)> wrote in message
> news:3f9af98e$0$13811$(E-Mail Removed)...
>
>>Hello,
>>
>>What kind of mask should I use with DecimalFormat class if I would like to
>>get allways two digits after decimalpoint? E.g. if input is 100.1 then
>>result should be 100.10.

>
>
> DecimalFormat df = new DecimalFormat("0.00");
>
> System.out.println(df.format(100.1)); // gives 100.10
>
>
>>Then second questions is that people is USA are using
>>dot as a separator in decimal numbers. But in Northern
>>Europe it's comma.

>
>
> Not in the UK it isn't


True, but then the OP did say they were in Scandinavia. From that point
of view the UK may not be in "Northern Europe"! The ISO standards also
prefer the comma form and they are used in the UK. As far as I can tell
the UK (and possibly Ireland) are the only European locales using '.' as
the decimal separator. In currencies, some countries use a currency
symbol as the divider (e.g. Portugal).

Mark Thornton

 
Reply With Quote
 
VisionSet
Guest
Posts: n/a
 
      10-26-2003

"Michael Borgwardt" <(E-Mail Removed)> wrote in message
news:bngc8c$106l0r$(E-Mail Removed)-berlin.de...
> VisionSet wrote:
> at is the most elegant way to
> >>implement this point/comma localized difference when handling decimal
> >>numbers?

> >
> > eh?
> > I've run the example code in java.text.DecimalFormat API, and can't see

any
> > country that uses anything other than decimal point.

>
> Then you were doing something wrong. Most European countries (definitely
> Germany, France, Belgium and the Netherlands) use a decimal comma.


Yep, I was looking at the wrong part of the output.

--
Mike W




 
Reply With Quote
 
VisionSet
Guest
Posts: n/a
 
      10-26-2003

"Mark Thornton" <(E-Mail Removed)> wrote in message
news:dVOmb.1644$(E-Mail Removed)...
> VisionSet wrote:
> >
> >>Then second questions is that people is USA are using
> >>dot as a separator in decimal numbers. But in Northern
> >>Europe it's comma.

> >
> >
> > Not in the UK it isn't

>
> True, but then the OP did say they were in Scandinavia. From that point
> of view the UK may not be in "Northern Europe"!


True, but I always took Northern Europe to mean none Mediteranean.

--
Mike W


 
Reply With Quote
 
Mark Thornton
Guest
Posts: n/a
 
      10-26-2003
VisionSet wrote:

> "Mark Thornton" <(E-Mail Removed)> wrote in message
> news:dVOmb.1644$(E-Mail Removed)...
>
>>VisionSet wrote:
>>
>>>>Then second questions is that people is USA are using
>>>>dot as a separator in decimal numbers. But in Northern
>>>>Europe it's comma.
>>>
>>>
>>>Not in the UK it isn't

>>
>>True, but then the OP did say they were in Scandinavia. From that point
>>of view the UK may not be in "Northern Europe"!

>
>
> True, but I always took Northern Europe to mean none Mediteranean.
>


So do I, but you never know. There are also many people here (UK) who
use "Europe" in a sense which doesn't include the UK. As in the old
joke: "Fog in the channel, Europe isolated!"

Mark Thornton

 
Reply With Quote
 
A Dahlman
Guest
Posts: n/a
 
      10-27-2003
Johnny wrote:
>
> Hello,
>
> What kind of mask should I use with DecimalFormat class if I would like to
> get allways two digits after decimalpoint? E.g. if input is 100.1 then
> result should be 100.10.
>
> Then second questions is that people is USA are using
> dot as a separator in decimal numbers. But in Northern
> Europe it's comma. What is the most elegant way to
> implement this point/comma localized difference when handling decimal
> numbers?
>
> Cheers,
>
> It's snow in the ground here in Scandinavia now


Using DecimalFormat and a mask already defeats Java's built-in international
localization features. Use NumberFormat.getInstance() or getCurrencyInstance()
instead. Americans, Canadians, Brits and Irishpersons should learn this habit,
too. The resulting object is still of type DecimalFormat, but it is localized,
depending on the location of the client that runs the program.

Usually it will not be necessary, but if you must, you can limit the decimal
places to 2 by using setMinimumFractionDigits( int ) and setMaximum...( int ),
which are part of the NumberFormat API.

Skål, Tony Dahlman

Hey, and in Austria, the first World Cup Slalom medals are being handed out.
We're in a hot spell (no rain since July in No. California, and fires raging
down south), but I can't wait for snow and skiing.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any common alternatives to java.text.DecimalFormat Jim Cobban Java 6 09-12-2005 10:10 AM
Setting decimal sign ("+" AND "-") in DecimalFormat ? Mark Sizzler Java 1 02-21-2005 08:01 PM
How to suppress final 0 with DecimalFormat? Adam Lipscombe Java 2 11-29-2004 08:51 PM
Weird Problem w/ DecimalFormat Cliff Java 5 05-12-2004 02:59 AM
Padding for DecimalFormat? Timo Nentwig Java 3 02-12-2004 05:06 AM



Advertisments