N
Neil Guyette
Hello,
I'm having problems figuring out why a conversion between a System.Single
type roundd when calling the object's ToString method. I'm pulling data out
of an OdbcDataReader which declares one of the columns as type Single.
Example:
OdbcDataReader odbcReader = odbcCmd.ExecuteReader();
odbcReader.Read();
// At this point the odbcReader has one row with one column, the column
value
// is 1000.08008 and the system type is System.Single. I want the value to
be cast
// to a string and have precision of 7 therefore the desired result should
be
//1000.0800800.
//I tried this but it doesn't work.
string s = odbcReader[0].ToString().ToString("F7");
//now s = 1000.0800000. it rounded
//I also tried this and yes it doesn't give me the right results
String s = Convert.ToSingle(odbcReader[0]).ToString("F7")
//s = 1000.0800000 still rounding!!
Why is the ToString() rounding the value? How do I stop it from happening
and get exactly the same value that is stored in odbcReader[0] (1000.08008).
Cheers!
I'm having problems figuring out why a conversion between a System.Single
type roundd when calling the object's ToString method. I'm pulling data out
of an OdbcDataReader which declares one of the columns as type Single.
Example:
OdbcDataReader odbcReader = odbcCmd.ExecuteReader();
odbcReader.Read();
// At this point the odbcReader has one row with one column, the column
value
// is 1000.08008 and the system type is System.Single. I want the value to
be cast
// to a string and have precision of 7 therefore the desired result should
be
//1000.0800800.
//I tried this but it doesn't work.
string s = odbcReader[0].ToString().ToString("F7");
//now s = 1000.0800000. it rounded
//I also tried this and yes it doesn't give me the right results
String s = Convert.ToSingle(odbcReader[0]).ToString("F7")
//s = 1000.0800000 still rounding!!
Why is the ToString() rounding the value? How do I stop it from happening
and get exactly the same value that is stored in odbcReader[0] (1000.08008).
Cheers!