|
|
|
start date: Thu, 19 Jul 2007 01:51:49 -0700,
posted on: microsoft.public.dotnet.framework.performance
back
| Thread Index |
|
1
unknown
|
|
2
Henning Krause [MVP - Exchange]
|
|
3
Bram
|
|
4
Mark_Parker
|
|
5
Jon Skeet [C# MVP]
|
|
6
Mark_Parker
|
|
7
cody
|
precision in double
Hi, I have the following problem:
I need to change the precision of double variable, but I don't want to
round it. Just cut unnecessary part.
For example:
I have: double d=0.3999999
I wan't to have: 0.39
Is there any method in .NET Framework that could help me?
Date:Thu, 19 Jul 2007 01:51:49 -0700
Author:
|
Re: precision in double
Hello,
just call Math.Round(d, 2);
Kind regards,
Henning Krause
wrote in message
news:1184835109.474544.22960@i13g2000prf.googlegroups.com...
> Hi, I have the following problem:
>
> I need to change the precision of double variable, but I don't want to
> round it. Just cut unnecessary part.
> For example:
>
> I have: double d=0.3999999
>
> I wan't to have: 0.39
>
> Is there any method in .NET Framework that could help me?
>
Date:Thu, 19 Jul 2007 11:37:27 +0200
Author:
|
Re: precision in double
Hi Henning,
I'm pretty sure that the result of Math.Round(0.39999999999, 2) == 0.4
and not 0.39. However, the following does work:
double value = 0.399999999999;
double rounded = Math.Round(value * 100.0) / 100.0;
Kind regards,
Bram Fokke
On 19 jul, 11:37, "Henning Krause [MVP - Exchange]"
wrote:
> Hello,
>
> just call Math.Round(d, 2);
>
> Kind regards,
> Henning Krause
>
> wrote in message
>
> news:1184835109.474544.22960@i13g2000prf.googlegroups.com...
>
> > Hi, I have the following problem:
>
> > I need to change the precision of double variable, but I don't want to
> > round it. Just cut unnecessary part.
> > For example:
>
> > I have: double d=0.3999999
>
> > I wan't to have: 0.39
>
> > Is there any method in .NET Framework that could help me?
Date:Fri, 20 Jul 2007 09:02:25 -0000
Author:
|
Re: precision in double
wrote:
> I need to change the precision of double variable, but I don't want to
> round it. Just cut unnecessary part.
It's not really clear what you mean.
> For example:
>
> I have: double d=0.3999999
>
> I wan't to have: 0.39
Isn't that just rounding it though? Could you give more information
about what you're trying to achieve?
--
Jon Skeet -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Date:Mon, 23 Jul 2007 19:37:44 +0100
Author:
|
RE: precision in double
Based on the OP's request, Math.Truncate is what is needed.
double value = 0.3999999;
double new_value = Math.Truncate(value * 100.0) / 100.0;
The code above sets new_value to 0.39.
"mamin@o2.pl" wrote:
> Hi, I have the following problem:
>
> I need to change the precision of double variable, but I don't want to
> round it. Just cut unnecessary part.
> For example:
>
> I have: double d=0.3999999
>
> I wan't to have: 0.39
>
> Is there any method in .NET Framework that could help me?
>
>
Date:Tue, 24 Jul 2007 17:40:01 -0700
Author:
|
Re: precision in double
"Bram" wrote:
> Hi Henning,
>
> I'm pretty sure that the result of Math.Round(0.39999999999, 2) == 0.4
> and not 0.39. However, the following does work:
>
> double value = 0.399999999999;
> double rounded = Math.Round(value * 100.0) / 100.0;
>
> Kind regards,
> Bram Fokke
On my machine, the code above sets rounded to 0.4, the same as in your first
example.
>
> On 19 jul, 11:37, "Henning Krause [MVP - Exchange]"
> wrote:
> > Hello,
> >
> > just call Math.Round(d, 2);
> >
> > Kind regards,
> > Henning Krause
> >
> > wrote in message
> >
> > news:1184835109.474544.22960@i13g2000prf.googlegroups.com...
> >
> > > Hi, I have the following problem:
> >
> > > I need to change the precision of double variable, but I don't want to
> > > round it. Just cut unnecessary part.
> > > For example:
> >
> > > I have: double d=0.3999999
> >
> > > I wan't to have: 0.39
> >
> > > Is there any method in .NET Framework that could help me?
>
>
>
Date:Tue, 24 Jul 2007 17:46:05 -0700
Author:
|
Re: precision in double
mamin@o2.pl wrote:
> Hi, I have the following problem:
>
> I need to change the precision of double variable, but I don't want to
> round it. Just cut unnecessary part.
> For example:
>
> I have: double d=0.3999999
>
> I wan't to have: 0.39
>
> Is there any method in .NET Framework that could help me?
>
maybe String.Format({0:n2}, myDouble);
is what you want.
Date:Tue, 07 Aug 2007 13:56:10 +0200
Author:
|
|
|