Convert.tosingle rounding problem

  • Thread starter Thread starter sony.m.2007
  • Start date Start date
S

sony.m.2007

Hi,
I have a problem in converting the string to single using
convert.tosingle.
convert.tosingle rounds of .99 to 1.00
my code as below
string st="99.99";
single st1=0.0F;
st1=Convert.ToSingle(st);
When i check the value of st1, it is 100.00.
Is there anyother argument to be passed into convert.tosingle function
to avoid rounding?

Thanks,
Sony
 
I have a problem in converting the string to single using
convert.tosingle.
convert.tosingle rounds of .99 to 1.00
my code as below
string st="99.99";
single st1=0.0F;
st1=Convert.ToSingle(st);
When i check the value of st1, it is 100.00.

How are you checking the value of st1?

Here's a short program demonstrating it working:

using System;
using System.Globalization;
using System.Threading;

class Test
{
static void Main()
{
float f1 = Convert.ToSingle("99.99");
float f2 = Convert.ToSingle("0.99");

Console.WriteLine(DoubleConverter.ToExactString(f1));
Console.WriteLine(DoubleConverter.ToExactString(f2));
}
}

DoubleConverter.cs can be downloaded from
http://www.yoda.arachsys.com/csharp/DoubleConverter.cs

Do you have a short but complete program demonstrating your issue?
 
Hi,
I have a problem in converting the string to single using
convert.tosingle.
convert.tosingle rounds of .99 to 1.00
my code as below
string st="99.99";
single st1=0.0F;
st1=Convert.ToSingle(st);
When i check the value of st1, it is 100.00.
Is there anyother argument to be passed into convert.tosingle function
to avoid rounding?

Thanks,
Sony

Ehhmm I got 99,99

string st = "99,99";
Single st1= 0.0F;
st1 = Convert.ToSingle(st);

//CY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top