Topic: 请教大家一个关于float类型数据写入sqlserver的问题

  Print this page

1.请教大家一个关于float类型数据写入sqlserver的问题 Copy to clipboard
Posted by: yb7711
Posted on: 2006-01-25 23:42

我在jsp程序中向sqlserver提交了一个float类型的数据,在sqlserver表中相应的数据项类型也是float类型的,但提交后在sqlserver中的数据与我提交的数据不同,比如我提交的是23.55,但数据库中显示的是23.5499992370605,请问大家这会是怎么回事呢?谢谢大家!

2.Re:请教大家一个关于float类型数据写入sqlserver的问题 [Re: yb7711] Copy to clipboard
Posted by: why
Posted on: 2006-01-25 23:56

Show us your code, and how you get 数据库中显示

Note that a float value in Java only has a precision of about 7 digits, and even if it is a double, the precision is still limited and is seldom an exact represtation of a decimal number.
For exact representation, "numeric" type has to be used.
Read http://www.cjsdn.net/post/view?bid=29&id=151465

3.Re:请教大家一个关于float类型数据写入sqlserver的问题 [Re: yb7711] Copy to clipboard
Posted by: why
Posted on: 2006-01-26 17:49

float in SQL Server (8 bytes) is equivalent to double in Java , so the issue is similar to the following:
float f = 23.55f;
double d = f;
System.out.println( d ); // prints 23.549999237060547

sqlserver表中相应的数据项类型应是real类型

4.Re:请教大家一个关于float类型数据写入sqlserver的问题 [Re: yb7711] Copy to clipboard
Posted by: why
Posted on: 2006-01-28 20:24

Your duplicated post on the Servlet/JSP/JSF board has been removed:
http://www.cjsdn.net/post/view?bid=51&id=168503

javadd replied on 2006-01-25
估计你在request.getParameter的时候做String to Double转换时没转换好

5.Re:请教大家一个关于float类型数据写入sqlserver的问题 [Re: yb7711] Copy to clipboard
Posted by: jackchengen
Posted on: 2006-02-19 16:49

java中的float类型相当于mysql 中的real类型
mysql 中的float类型相当与java中的double


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923