all groups > sql server programming > august 2007 >
You're in the sql server programming group:
Why float value will change when it is saved to DB
sql server programming:
I feel it strange that after float value 1.19 saved to DB, and it becomes to 1.189999..., but not all the values has this problem, only a few transactions will have this problem. My Table Structure ColumnnName float 8 not null. My SP Insert TableName(ColumnName) select ColumnName From openxml (@hDoc,'//Reply') with ( ColumnName float './ColumnName' ) Can anyone help me? Thanks in advance.
But I use the same table stucture and same SP in our Test and Dev enviroment, No such thing happen. Also I put the same xml to excute in our Test enviroment, it should be fine. Does it caused by enviroment difference or it will be saved randomly. [quoted text, click to view] "Dan Guzman" wrote: > Not all decimal values can be exactly represented by float and real data > types. The behavior follows the IEEE 754 specification and is why these a > labeled as approximate types in the Books Online. > > If you need exact decimal values, use a decimal data type. > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... > >I feel it strange that after float value 1.19 saved to DB, and it becomes > >to > > 1.189999..., but not all the values has this problem, only a few > > transactions > > will have this problem. > > > > My Table Structure > > ColumnnName float 8 not null. > > > > My SP > > Insert TableName(ColumnName) > > select ColumnName > > From openxml (@hDoc,'//Reply') > > with ( > > ColumnName float './ColumnName' > > ) > > > > Can anyone help me? Thanks in advance. > >
Not all decimal values can be exactly represented by float and real data types. The behavior follows the IEEE 754 specification and is why these a labeled as approximate types in the Books Online. If you need exact decimal values, use a decimal data type. -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... >I feel it strange that after float value 1.19 saved to DB, and it becomes >to > 1.189999..., but not all the values has this problem, only a few > transactions > will have this problem. > > My Table Structure > ColumnnName float 8 not null. > > My SP > Insert TableName(ColumnName) > select ColumnName > From openxml (@hDoc,'//Reply') > with ( > ColumnName float './ColumnName' > ) > > Can anyone help me? Thanks in advance. >
[quoted text, click to view] > Because Sql server 2005 will format the value, but sql server 2000 will > not. > So my eye has cheated me.
More accurately, SSMS will round the float value for display but Query Analyzer, OSQL and SQLCMD will not. The underlying database value is the same in both SQL 2000 and SQL 2005. I'm glad I was able to help you out. -- Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:500B18CD-97A6-4960-B4E5-5E69F7844B5B@microsoft.com... > Thanks, you are right. > > Because Sql server 2005 will format the value, but sql server 2000 will > not. > So my eye has cheated me. > > Thanks. > > "Dan Guzman" wrote: > >> > But I use the same table stucture and same SP in our Test and Dev >> > enviroment, No such thing happen. Also I put the same xml to excute in >> > our >> > Test enviroment, it should be fine. Does it caused by enviroment >> > difference >> > or it will be saved randomly. >> >> I expect consistent results regardless of the environment as long as the >> same value is inserted. The behavior may appear random because only >> certain >> float values are affected For example: >> >> SELECT CAST(1.19 as float) --1.1899999999999999 >> SELECT CAST(1.29 as float) --1.29 >> >> Also, tools like SSMS may format values for display purposes so you will >> see >> 1.19 in the GUI even though the underlying database value is >> 1.1899999999999999. SQLCMD will show the actual value: >> >> SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" >> >> -- >> Hope this helps. >> >> Dan Guzman >> SQL Server MVP >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... >> > >> > But I use the same table stucture and same SP in our Test and Dev >> > enviroment, No such thing happen. Also I put the same xml to excute in >> > our >> > Test enviroment, it should be fine. Does it caused by enviroment >> > difference >> > or it will be saved randomly. >> > >> > "Dan Guzman" wrote: >> > >> >> Not all decimal values can be exactly represented by float and real >> >> data >> >> types. The behavior follows the IEEE 754 specification and is why >> >> these >> >> a >> >> labeled as approximate types in the Books Online. >> >> >> >> If you need exact decimal values, use a decimal data type. >> >> >> >> -- >> >> Hope this helps. >> >> >> >> Dan Guzman >> >> SQL Server MVP >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... >> >> >I feel it strange that after float value 1.19 saved to DB, and it >> >> >becomes >> >> >to >> >> > 1.189999..., but not all the values has this problem, only a few >> >> > transactions >> >> > will have this problem. >> >> > >> >> > My Table Structure >> >> > ColumnnName float 8 not null. >> >> > >> >> > My SP >> >> > Insert TableName(ColumnName) >> >> > select ColumnName >> >> > From openxml (@hDoc,'//Reply') >> >> > with ( >> >> > ColumnName float './ColumnName' >> >> > ) >> >> > >> >> > Can anyone help me? Thanks in advance. >> >> > >> >> >>
Thanks, you are right. Because Sql server 2005 will format the value, but sql server 2000 will not. So my eye has cheated me. Thanks. [quoted text, click to view] "Dan Guzman" wrote: > > But I use the same table stucture and same SP in our Test and Dev > > enviroment, No such thing happen. Also I put the same xml to excute in our > > Test enviroment, it should be fine. Does it caused by enviroment > > difference > > or it will be saved randomly. > > I expect consistent results regardless of the environment as long as the > same value is inserted. The behavior may appear random because only certain > float values are affected For example: > > SELECT CAST(1.19 as float) --1.1899999999999999 > SELECT CAST(1.29 as float) --1.29 > > Also, tools like SSMS may format values for display purposes so you will see > 1.19 in the GUI even though the underlying database value is > 1.1899999999999999. SQLCMD will show the actual value: > > SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... > > > > But I use the same table stucture and same SP in our Test and Dev > > enviroment, No such thing happen. Also I put the same xml to excute in our > > Test enviroment, it should be fine. Does it caused by enviroment > > difference > > or it will be saved randomly. > > > > "Dan Guzman" wrote: > > > >> Not all decimal values can be exactly represented by float and real data > >> types. The behavior follows the IEEE 754 specification and is why these > >> a > >> labeled as approximate types in the Books Online. > >> > >> If you need exact decimal values, use a decimal data type. > >> > >> -- > >> Hope this helps. > >> > >> Dan Guzman > >> SQL Server MVP > >> > >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... > >> >I feel it strange that after float value 1.19 saved to DB, and it > >> >becomes > >> >to > >> > 1.189999..., but not all the values has this problem, only a few > >> > transactions > >> > will have this problem. > >> > > >> > My Table Structure > >> > ColumnnName float 8 not null. > >> > > >> > My SP > >> > Insert TableName(ColumnName) > >> > select ColumnName > >> > From openxml (@hDoc,'//Reply') > >> > with ( > >> > ColumnName float './ColumnName' > >> > ) > >> > > >> > Can anyone help me? Thanks in advance. > >> > > >>
[quoted text, click to view] > But I use the same table stucture and same SP in our Test and Dev > enviroment, No such thing happen. Also I put the same xml to excute in our > Test enviroment, it should be fine. Does it caused by enviroment > difference > or it will be saved randomly.
I expect consistent results regardless of the environment as long as the same value is inserted. The behavior may appear random because only certain float values are affected For example: SELECT CAST(1.19 as float) --1.1899999999999999 SELECT CAST(1.29 as float) --1.29 Also, tools like SSMS may format values for display purposes so you will see 1.19 in the GUI even though the underlying database value is 1.1899999999999999. SQLCMD will show the actual value: SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... > > But I use the same table stucture and same SP in our Test and Dev > enviroment, No such thing happen. Also I put the same xml to excute in our > Test enviroment, it should be fine. Does it caused by enviroment > difference > or it will be saved randomly. > > "Dan Guzman" wrote: > >> Not all decimal values can be exactly represented by float and real data >> types. The behavior follows the IEEE 754 specification and is why these >> a >> labeled as approximate types in the Books Online. >> >> If you need exact decimal values, use a decimal data type. >> >> -- >> Hope this helps. >> >> Dan Guzman >> SQL Server MVP >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... >> >I feel it strange that after float value 1.19 saved to DB, and it >> >becomes >> >to >> > 1.189999..., but not all the values has this problem, only a few >> > transactions >> > will have this problem. >> > >> > My Table Structure >> > ColumnnName float 8 not null. >> > >> > My SP >> > Insert TableName(ColumnName) >> > select ColumnName >> > From openxml (@hDoc,'//Reply') >> > with ( >> > ColumnName float './ColumnName' >> > ) >> > >> > Can anyone help me? Thanks in advance. >> > >>
Thank you so much. You are really handing. But I have one more silly question, if I use SSMS, how can I get the value as what I get by Query Analyzer 2000? Thanks in advance. [quoted text, click to view] "Dan Guzman" wrote: > > Because Sql server 2005 will format the value, but sql server 2000 will > > not. > > So my eye has cheated me. > > More accurately, SSMS will round the float value for display but Query > Analyzer, OSQL and SQLCMD will not. The underlying database value is the > same in both SQL 2000 and SQL 2005. > > I'm glad I was able to help you out. > > -- > Dan Guzman > SQL Server MVP > > "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > news:500B18CD-97A6-4960-B4E5-5E69F7844B5B@microsoft.com... > > Thanks, you are right. > > > > Because Sql server 2005 will format the value, but sql server 2000 will > > not. > > So my eye has cheated me. > > > > Thanks. > > > > "Dan Guzman" wrote: > > > >> > But I use the same table stucture and same SP in our Test and Dev > >> > enviroment, No such thing happen. Also I put the same xml to excute in > >> > our > >> > Test enviroment, it should be fine. Does it caused by enviroment > >> > difference > >> > or it will be saved randomly. > >> > >> I expect consistent results regardless of the environment as long as the > >> same value is inserted. The behavior may appear random because only > >> certain > >> float values are affected For example: > >> > >> SELECT CAST(1.19 as float) --1.1899999999999999 > >> SELECT CAST(1.29 as float) --1.29 > >> > >> Also, tools like SSMS may format values for display purposes so you will > >> see > >> 1.19 in the GUI even though the underlying database value is > >> 1.1899999999999999. SQLCMD will show the actual value: > >> > >> SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" > >> > >> -- > >> Hope this helps. > >> > >> Dan Guzman > >> SQL Server MVP > >> > >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > >> news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... > >> > > >> > But I use the same table stucture and same SP in our Test and Dev > >> > enviroment, No such thing happen. Also I put the same xml to excute in > >> > our > >> > Test enviroment, it should be fine. Does it caused by enviroment > >> > difference > >> > or it will be saved randomly. > >> > > >> > "Dan Guzman" wrote: > >> > > >> >> Not all decimal values can be exactly represented by float and real > >> >> data > >> >> types. The behavior follows the IEEE 754 specification and is why > >> >> these > >> >> a > >> >> labeled as approximate types in the Books Online. > >> >> > >> >> If you need exact decimal values, use a decimal data type. > >> >> > >> >> -- > >> >> Hope this helps. > >> >> > >> >> Dan Guzman > >> >> SQL Server MVP > >> >> > >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > >> >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... > >> >> >I feel it strange that after float value 1.19 saved to DB, and it > >> >> >becomes > >> >> >to > >> >> > 1.189999..., but not all the values has this problem, only a few > >> >> > transactions > >> >> > will have this problem. > >> >> > > >> >> > My Table Structure > >> >> > ColumnnName float 8 not null. > >> >> > > >> >> > My SP > >> >> > Insert TableName(ColumnName) > >> >> > select ColumnName > >> >> > From openxml (@hDoc,'//Reply') > >> >> > with ( > >> >> > ColumnName float './ColumnName' > >> >> > ) > >> >> > > >> >> > Can anyone help me? Thanks in advance. > >> >> > > >> >> > >>
Thanks. Got it. Hope this function can be added in later version. [quoted text, click to view] "Dan Guzman" wrote: > > But I have one more silly question, if I use SSMS, how can I get the value > > as what I get by Query Analyzer 2000? > > Sorry, but I don't believe SSMS provides the option to change the display > behavior. You'll need to use SQLCMD in that case. > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > news:A61D25DD-1FA0-48E2-AB9A-CD33C1B76A84@microsoft.com... > > Thank you so much. You are really handing. > > > > But I have one more silly question, if I use SSMS, how can I get the value > > as what I get by Query Analyzer 2000? > > > > Thanks in advance. > > > > > > > > "Dan Guzman" wrote: > > > >> > Because Sql server 2005 will format the value, but sql server 2000 will > >> > not. > >> > So my eye has cheated me. > >> > >> More accurately, SSMS will round the float value for display but Query > >> Analyzer, OSQL and SQLCMD will not. The underlying database value is the > >> same in both SQL 2000 and SQL 2005. > >> > >> I'm glad I was able to help you out. > >> > >> -- > >> Dan Guzman > >> SQL Server MVP > >> > >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > >> news:500B18CD-97A6-4960-B4E5-5E69F7844B5B@microsoft.com... > >> > Thanks, you are right. > >> > > >> > Because Sql server 2005 will format the value, but sql server 2000 will > >> > not. > >> > So my eye has cheated me. > >> > > >> > Thanks. > >> > > >> > "Dan Guzman" wrote: > >> > > >> >> > But I use the same table stucture and same SP in our Test and Dev > >> >> > enviroment, No such thing happen. Also I put the same xml to excute > >> >> > in > >> >> > our > >> >> > Test enviroment, it should be fine. Does it caused by enviroment > >> >> > difference > >> >> > or it will be saved randomly. > >> >> > >> >> I expect consistent results regardless of the environment as long as > >> >> the > >> >> same value is inserted. The behavior may appear random because only > >> >> certain > >> >> float values are affected For example: > >> >> > >> >> SELECT CAST(1.19 as float) --1.1899999999999999 > >> >> SELECT CAST(1.29 as float) --1.29 > >> >> > >> >> Also, tools like SSMS may format values for display purposes so you > >> >> will > >> >> see > >> >> 1.19 in the GUI even though the underlying database value is > >> >> 1.1899999999999999. SQLCMD will show the actual value: > >> >> > >> >> SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" > >> >> > >> >> -- > >> >> Hope this helps. > >> >> > >> >> Dan Guzman > >> >> SQL Server MVP > >> >> > >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > >> >> news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... > >> >> > > >> >> > But I use the same table stucture and same SP in our Test and Dev > >> >> > enviroment, No such thing happen. Also I put the same xml to excute > >> >> > in > >> >> > our > >> >> > Test enviroment, it should be fine. Does it caused by enviroment > >> >> > difference > >> >> > or it will be saved randomly. > >> >> > > >> >> > "Dan Guzman" wrote: > >> >> > > >> >> >> Not all decimal values can be exactly represented by float and real > >> >> >> data > >> >> >> types. The behavior follows the IEEE 754 specification and is why > >> >> >> these > >> >> >> a > >> >> >> labeled as approximate types in the Books Online. > >> >> >> > >> >> >> If you need exact decimal values, use a decimal data type. > >> >> >> > >> >> >> -- > >> >> >> Hope this helps. > >> >> >> > >> >> >> Dan Guzman > >> >> >> SQL Server MVP > >> >> >> > >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in > >> >> >> message > >> >> >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... > >> >> >> >I feel it strange that after float value 1.19 saved to DB, and it > >> >> >> >becomes > >> >> >> >to > >> >> >> > 1.189999..., but not all the values has this problem, only a few > >> >> >> > transactions > >> >> >> > will have this problem. > >> >> >> > > >> >> >> > My Table Structure > >> >> >> > ColumnnName float 8 not null. > >> >> >> > > >> >> >> > My SP > >> >> >> > Insert TableName(ColumnName) > >> >> >> > select ColumnName > >> >> >> > From openxml (@hDoc,'//Reply') > >> >> >> > with ( > >> >> >> > ColumnName float './ColumnName' > >> >> >> > ) > >> >> >> > > >> >> >> > Can anyone help me? Thanks in advance. > >> >> >> > > >> >> >> > >> >> > >>
[quoted text, click to view] > But I have one more silly question, if I use SSMS, how can I get the value > as what I get by Query Analyzer 2000?
Sorry, but I don't believe SSMS provides the option to change the display behavior. You'll need to use SQLCMD in that case. -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:A61D25DD-1FA0-48E2-AB9A-CD33C1B76A84@microsoft.com... > Thank you so much. You are really handing. > > But I have one more silly question, if I use SSMS, how can I get the value > as what I get by Query Analyzer 2000? > > Thanks in advance. > > > > "Dan Guzman" wrote: > >> > Because Sql server 2005 will format the value, but sql server 2000 will >> > not. >> > So my eye has cheated me. >> >> More accurately, SSMS will round the float value for display but Query >> Analyzer, OSQL and SQLCMD will not. The underlying database value is the >> same in both SQL 2000 and SQL 2005. >> >> I'm glad I was able to help you out. >> >> -- >> Dan Guzman >> SQL Server MVP >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> news:500B18CD-97A6-4960-B4E5-5E69F7844B5B@microsoft.com... >> > Thanks, you are right. >> > >> > Because Sql server 2005 will format the value, but sql server 2000 will >> > not. >> > So my eye has cheated me. >> > >> > Thanks. >> > >> > "Dan Guzman" wrote: >> > >> >> > But I use the same table stucture and same SP in our Test and Dev >> >> > enviroment, No such thing happen. Also I put the same xml to excute >> >> > in >> >> > our >> >> > Test enviroment, it should be fine. Does it caused by enviroment >> >> > difference >> >> > or it will be saved randomly. >> >> >> >> I expect consistent results regardless of the environment as long as >> >> the >> >> same value is inserted. The behavior may appear random because only >> >> certain >> >> float values are affected For example: >> >> >> >> SELECT CAST(1.19 as float) --1.1899999999999999 >> >> SELECT CAST(1.29 as float) --1.29 >> >> >> >> Also, tools like SSMS may format values for display purposes so you >> >> will >> >> see >> >> 1.19 in the GUI even though the underlying database value is >> >> 1.1899999999999999. SQLCMD will show the actual value: >> >> >> >> SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" >> >> >> >> -- >> >> Hope this helps. >> >> >> >> Dan Guzman >> >> SQL Server MVP >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> >> news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... >> >> > >> >> > But I use the same table stucture and same SP in our Test and Dev >> >> > enviroment, No such thing happen. Also I put the same xml to excute >> >> > in >> >> > our >> >> > Test enviroment, it should be fine. Does it caused by enviroment >> >> > difference >> >> > or it will be saved randomly. >> >> > >> >> > "Dan Guzman" wrote: >> >> > >> >> >> Not all decimal values can be exactly represented by float and real >> >> >> data >> >> >> types. The behavior follows the IEEE 754 specification and is why >> >> >> these >> >> >> a >> >> >> labeled as approximate types in the Books Online. >> >> >> >> >> >> If you need exact decimal values, use a decimal data type. >> >> >> >> >> >> -- >> >> >> Hope this helps. >> >> >> >> >> >> Dan Guzman >> >> >> SQL Server MVP >> >> >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in >> >> >> message >> >> >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... >> >> >> >I feel it strange that after float value 1.19 saved to DB, and it >> >> >> >becomes >> >> >> >to >> >> >> > 1.189999..., but not all the values has this problem, only a few >> >> >> > transactions >> >> >> > will have this problem. >> >> >> > >> >> >> > My Table Structure >> >> >> > ColumnnName float 8 not null. >> >> >> > >> >> >> > My SP >> >> >> > Insert TableName(ColumnName) >> >> >> > select ColumnName >> >> >> > From openxml (@hDoc,'//Reply') >> >> >> > with ( >> >> >> > ColumnName float './ColumnName' >> >> >> > ) >> >> >> > >> >> >> > Can anyone help me? Thanks in advance. >> >> >> > >> >> >> >> >> >>
[quoted text, click to view] > Thanks. Got it. Hope this function can be added in later version.
Me too. There is a suggestion on Connect for this but it current closed by design. If this is important to you, consider voting accordingly: http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=126117 -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:702F5464-2FFD-4717-A902-93A1F76E358F@microsoft.com... > Thanks. Got it. Hope this function can be added in later version. > > "Dan Guzman" wrote: > >> > But I have one more silly question, if I use SSMS, how can I get the >> > value >> > as what I get by Query Analyzer 2000? >> >> Sorry, but I don't believe SSMS provides the option to change the display >> behavior. You'll need to use SQLCMD in that case. >> >> -- >> Hope this helps. >> >> Dan Guzman >> SQL Server MVP >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> news:A61D25DD-1FA0-48E2-AB9A-CD33C1B76A84@microsoft.com... >> > Thank you so much. You are really handing. >> > >> > But I have one more silly question, if I use SSMS, how can I get the >> > value >> > as what I get by Query Analyzer 2000? >> > >> > Thanks in advance. >> > >> > >> > >> > "Dan Guzman" wrote: >> > >> >> > Because Sql server 2005 will format the value, but sql server 2000 >> >> > will >> >> > not. >> >> > So my eye has cheated me. >> >> >> >> More accurately, SSMS will round the float value for display but Query >> >> Analyzer, OSQL and SQLCMD will not. The underlying database value is >> >> the >> >> same in both SQL 2000 and SQL 2005. >> >> >> >> I'm glad I was able to help you out. >> >> >> >> -- >> >> Dan Guzman >> >> SQL Server MVP >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message >> >> news:500B18CD-97A6-4960-B4E5-5E69F7844B5B@microsoft.com... >> >> > Thanks, you are right. >> >> > >> >> > Because Sql server 2005 will format the value, but sql server 2000 >> >> > will >> >> > not. >> >> > So my eye has cheated me. >> >> > >> >> > Thanks. >> >> > >> >> > "Dan Guzman" wrote: >> >> > >> >> >> > But I use the same table stucture and same SP in our Test and Dev >> >> >> > enviroment, No such thing happen. Also I put the same xml to >> >> >> > excute >> >> >> > in >> >> >> > our >> >> >> > Test enviroment, it should be fine. Does it caused by enviroment >> >> >> > difference >> >> >> > or it will be saved randomly. >> >> >> >> >> >> I expect consistent results regardless of the environment as long >> >> >> as >> >> >> the >> >> >> same value is inserted. The behavior may appear random because >> >> >> only >> >> >> certain >> >> >> float values are affected For example: >> >> >> >> >> >> SELECT CAST(1.19 as float) --1.1899999999999999 >> >> >> SELECT CAST(1.29 as float) --1.29 >> >> >> >> >> >> Also, tools like SSMS may format values for display purposes so you >> >> >> will >> >> >> see >> >> >> 1.19 in the GUI even though the underlying database value is >> >> >> 1.1899999999999999. SQLCMD will show the actual value: >> >> >> >> >> >> SQLCMD -E -S MyServer -Q"SELECT CAST(1.19 AS float)" >> >> >> >> >> >> -- >> >> >> Hope this helps. >> >> >> >> >> >> Dan Guzman >> >> >> SQL Server MVP >> >> >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in >> >> >> message >> >> >> news:D3C29011-3B0A-48BC-A14C-E53073BBF56D@microsoft.com... >> >> >> > >> >> >> > But I use the same table stucture and same SP in our Test and Dev >> >> >> > enviroment, No such thing happen. Also I put the same xml to >> >> >> > excute >> >> >> > in >> >> >> > our >> >> >> > Test enviroment, it should be fine. Does it caused by enviroment >> >> >> > difference >> >> >> > or it will be saved randomly. >> >> >> > >> >> >> > "Dan Guzman" wrote: >> >> >> > >> >> >> >> Not all decimal values can be exactly represented by float and >> >> >> >> real >> >> >> >> data >> >> >> >> types. The behavior follows the IEEE 754 specification and is >> >> >> >> why >> >> >> >> these >> >> >> >> a >> >> >> >> labeled as approximate types in the Books Online. >> >> >> >> >> >> >> >> If you need exact decimal values, use a decimal data type. >> >> >> >> >> >> >> >> -- >> >> >> >> Hope this helps. >> >> >> >> >> >> >> >> Dan Guzman >> >> >> >> SQL Server MVP >> >> >> >> >> >> >> >> "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in >> >> >> >> message >> >> >> >> news:FB45900E-EF50-4EB7-9D45-4C2FD582C961@microsoft.com... >> >> >> >> >I feel it strange that after float value 1.19 saved to DB, and >> >> >> >> >it >> >> >> >> >becomes >> >> >> >> >to >> >> >> >> > 1.189999..., but not all the values has this problem, only a >> >> >> >> > few >> >> >> >> > transactions >> >> >> >> > will have this problem. >> >> >> >> > >> >> >> >> > My Table Structure >> >> >> >> > ColumnnName float 8 not null. >> >> >> >> > >> >> >> >> > My SP >> >> >> >> > Insert TableName(ColumnName) >> >> >> >> > select ColumnName >> >> >> >> > From openxml (@hDoc,'//Reply') >> >> >> >> > with ( >> >> >> >> > ColumnName float './ColumnName' >> >> >> >> > ) >> >> >> >> > >> >> >> >> > Can anyone help me? Thanks in advance. >> >> >> >> > >> >> >> >> >> >> >> >> >> >>
On Aug 27, 6:28 am, "Dan Guzman" <guzma...@nospam- [quoted text, click to view] online.sbcglobal.net> wrote: > > But I use the same table stucture and same SP in our Test and Dev > > enviroment, No such thing happen. Also I put the same xml to excute in our > > Test enviroment, it should be fine. Does it caused by enviroment > > difference > > or it will be saved randomly. > > I expect consistent results regardless of the environment as long as the > same value is inserted. The behavior may appear random because only certain > float values are affected For example: > > SELECT CAST(1.19 as float) --1.1899999999999999 > SELECT CAST(1.29 as float) --1.29 >
Dan, I think it is not random when you consider how these numbers look in binary format. Alex Kuznetsov, SQL Server MVP http://sqlserver-tips.blogspot.com/
Thank you all , Dan has made me understood. Float value is stored in a arthimatic expression, and its value is caculated in run time. It that right? So it should not be radom, because the same number is converted to the same expression. Please tell me if I'm wrong. Thanks. [quoted text, click to view] "Dan Guzman" wrote: > > Dan, I think it is not random when you consider how these numbers look > > in binary format. > > I agree. I was trying to convey to George that float behavior is not random > but might appears so because not all values are affected. > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > "Alex Kuznetsov" <alkuzo@gmail.com> wrote in message > news:1188485300.179833.278640@r34g2000hsd.googlegroups.com... > > On Aug 27, 6:28 am, "Dan Guzman" <guzma...@nospam- > > online.sbcglobal.net> wrote: > >> > But I use the same table stucture and same SP in our Test and Dev > >> > enviroment, No such thing happen. Also I put the same xml to excute in > >> > our > >> > Test enviroment, it should be fine. Does it caused by enviroment > >> > difference > >> > or it will be saved randomly. > >> > >> I expect consistent results regardless of the environment as long as the > >> same value is inserted. The behavior may appear random because only > >> certain > >> float values are affected For example: > >> > >> SELECT CAST(1.19 as float) --1.1899999999999999 > >> SELECT CAST(1.29 as float) --1.29 > >> > > > > Dan, I think it is not random when you consider how these numbers look > > in binary format. > > > > Alex Kuznetsov, SQL Server MVP > > http://sqlserver-tips.blogspot.com/ > >
[quoted text, click to view] > Dan, I think it is not random when you consider how these numbers look > in binary format.
I agree. I was trying to convey to George that float behavior is not random but might appears so because not all values are affected. -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "Alex Kuznetsov" <alkuzo@gmail.com> wrote in message news:1188485300.179833.278640@r34g2000hsd.googlegroups.com... > On Aug 27, 6:28 am, "Dan Guzman" <guzma...@nospam- > online.sbcglobal.net> wrote: >> > But I use the same table stucture and same SP in our Test and Dev >> > enviroment, No such thing happen. Also I put the same xml to excute in >> > our >> > Test enviroment, it should be fine. Does it caused by enviroment >> > difference >> > or it will be saved randomly. >> >> I expect consistent results regardless of the environment as long as the >> same value is inserted. The behavior may appear random because only >> certain >> float values are affected For example: >> >> SELECT CAST(1.19 as float) --1.1899999999999999 >> SELECT CAST(1.29 as float) --1.29 >> > > Dan, I think it is not random when you consider how these numbers look > in binary format. > > Alex Kuznetsov, SQL Server MVP > http://sqlserver-tips.blogspot.com/ >
Great, Thank you. In this discussion, I learn more than expected. [quoted text, click to view] "Dan Guzman" wrote: > > Thank you all , Dan has made me understood. Float value is stored in a > > arthimatic expression, and its value is caculated in run time. > > I'm not sure whether or not your understanding is complete. I think it is > more correct to say that the specified decimal value is converted to float > at run time and converting that float value back to decimal will not > necessarily yield the original decimal value. You can read more about IEEE > 754 at http://en.wikipedia.org/wiki/IEEE_754. Here is the relevant exceprt > from the Books Online: > > <Excerpt > href="ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/686eb8a8-fc51-4118-9ee2-3c2db9998f06.htm"> > > The float and real data types are known as approximate data types. The > behavior of float and real follows the IEEE 754 specification on approximate > numeric data types. > > Approximate numeric data types do not store the exact values specified for > many numbers; they store an extremely close approximation of the value. For > many applications, the tiny difference between the specified value and the > stored approximation is not noticeable. At times, though, the difference > becomes noticeable. Because of the approximate nature of the float and real > data types, do not use these data types when exact numeric behavior is > required, such as in financial applications, in operations involving > rounding, or in equality checks. Instead, use the integer, decimal, money, > or smallmoney data types. > > Avoid using float or real columns in WHERE clause search conditions, > especially the = and <> operators. It is best to limit float and real > columns to > or < comparisons. > > The IEEE 754 specification provides four rounding modes: round to nearest, > round up, round down, and round to zero. Microsoft SQL Server 2005 uses > round up. All are accurate to the guaranteed precision but can result in > slightly different floating-point values. Because the binary representation > of a floating-point number may use one of many legal rounding schemes, it is > impossible to reliably quantify a floating-point value. > > </Excerpt> > > > So it should not be radom, because the same number is converted to the > > same > > expression. > > Correct. > > -- > Hope this helps. > > Dan Guzman > SQL Server MVP > > "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message > news:0BCB4BDF-3999-49DD-B21D-6B97377A3105@microsoft.com... > > Thank you all , Dan has made me understood. Float value is stored in a > > arthimatic expression, and its value is caculated in run time. It that > > right? > > So it should not be radom, because the same number is converted to the > > same > > expression. > > > > Please tell me if I'm wrong. Thanks. > > > > "Dan Guzman" wrote: > > > >> > Dan, I think it is not random when you consider how these numbers look > >> > in binary format. > >> > >> I agree. I was trying to convey to George that float behavior is not > >> random > >> but might appears so because not all values are affected. > >> > >> -- > >> Hope this helps. > >> > >> Dan Guzman > >> SQL Server MVP > >> > >> "Alex Kuznetsov" <alkuzo@gmail.com> wrote in message > >> news:1188485300.179833.278640@r34g2000hsd.googlegroups.com... > >> > On Aug 27, 6:28 am, "Dan Guzman" <guzma...@nospam- > >> > online.sbcglobal.net> wrote: > >> >> > But I use the same table stucture and same SP in our Test and Dev > >> >> > enviroment, No such thing happen. Also I put the same xml to excute > >> >> > in > >> >> > our > >> >> > Test enviroment, it should be fine. Does it caused by enviroment > >> >> > difference > >> >> > or it will be saved randomly. > >> >> > >> >> I expect consistent results regardless of the environment as long as > >> >> the > >> >> same value is inserted. The behavior may appear random because only > >> >> certain > >> >> float values are affected For example: > >> >> > >> >> SELECT CAST(1.19 as float) --1.1899999999999999 > >> >> SELECT CAST(1.29 as float) --1.29 > >> >> > >> > > >> > Dan, I think it is not random when you consider how these numbers look > >> > in binary format. > >> > > >> > Alex Kuznetsov, SQL Server MVP > >> > http://sqlserver-tips.blogspot.com/ > >> > > >>
[quoted text, click to view] > Thank you all , Dan has made me understood. Float value is stored in a > arthimatic expression, and its value is caculated in run time.
I'm not sure whether or not your understanding is complete. I think it is more correct to say that the specified decimal value is converted to float at run time and converting that float value back to decimal will not necessarily yield the original decimal value. You can read more about IEEE 754 at http://en.wikipedia.org/wiki/IEEE_754. Here is the relevant exceprt from the Books Online: <Excerpt href="ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/686eb8a8-fc51-4118-9ee2-3c2db9998f06.htm"> The float and real data types are known as approximate data types. The behavior of float and real follows the IEEE 754 specification on approximate numeric data types. Approximate numeric data types do not store the exact values specified for many numbers; they store an extremely close approximation of the value. For many applications, the tiny difference between the specified value and the stored approximation is not noticeable. At times, though, the difference becomes noticeable. Because of the approximate nature of the float and real data types, do not use these data types when exact numeric behavior is required, such as in financial applications, in operations involving rounding, or in equality checks. Instead, use the integer, decimal, money, or smallmoney data types. Avoid using float or real columns in WHERE clause search conditions, especially the = and <> operators. It is best to limit float and real columns to > or < comparisons. The IEEE 754 specification provides four rounding modes: round to nearest, round up, round down, and round to zero. Microsoft SQL Server 2005 uses round up. All are accurate to the guaranteed precision but can result in slightly different floating-point values. Because the binary representation of a floating-point number may use one of many legal rounding schemes, it is impossible to reliably quantify a floating-point value. </Excerpt> [quoted text, click to view] > So it should not be radom, because the same number is converted to the > same > expression.
Correct. -- Hope this helps. Dan Guzman SQL Server MVP [quoted text, click to view] "George Shui" <GeorgeShui@discussions.microsoft.com> wrote in message news:0BCB4BDF-3999-49DD-B21D-6B97377A3105@microsoft.com... > Thank you all , Dan has made me understood. Float value is stored in a > arthimatic expression, and its value is caculated in run time. It that > right? > So it should not be radom, because the same number is converted to the > same > expression. > > Please tell me if I'm wrong. Thanks. > > "Dan Guzman" wrote: > >> > Dan, I think it is not random when you consider how these numbers look >> > in binary format. >> >> I agree. I was trying to convey to George that float behavior is not >> random >> but might appears so because not all values are affected. >> >> -- >> Hope this helps. >> >> Dan Guzman >> SQL Server MVP >> >> "Alex Kuznetsov" <alkuzo@gmail.com> wrote in message >> news:1188485300.179833.278640@r34g2000hsd.googlegroups.com... >> > On Aug 27, 6:28 am, "Dan Guzman" <guzma...@nospam- >> > online.sbcglobal.net> wrote: >> >> > But I use the same table stucture and same SP in our Test and Dev >> >> > enviroment, No such thing happen. Also I put the same xml to excute >> >> > in >> >> > our >> >> > Test enviroment, it should be fine. Does it caused by enviroment >> >> > difference >> >> > or it will be saved randomly. >> >> >> >> I expect consistent results regardless of the environment as long as >> >> the >> >> same value is inserted. The behavior may appear random because only >> >> certain >> >> float values are affected For example: >> >> >> >> SELECT CAST(1.19 as float) --1.1899999999999999 >> >> SELECT CAST(1.29 as float) --1.29 >> >> >> > >> > Dan, I think it is not random when you consider how these numbers look >> > in binary format. >> > >> > Alex Kuznetsov, SQL Server MVP >> > http://sqlserver-tips.blogspot.com/ >> > >>
Don't see what you're looking for? Try a search.
|
|
|