转换为字符串值时,十进制数据类型值给出不同的值 [英] Decimal data type value is giving different value when converted to string value

查看:81
本文介绍了转换为字符串值时,十进制数据类型值给出不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

在我的Web应用程序中(在Visual Studio 2003中进行设计),我正在使用一个声明为 DECIMAL 数据类型的变量.

hello,

In my web application, designing in visual studio 2003, I am using a variable declared as DECIMAL data type.

Dim variable1 as Decimal = 123456789



在为 variable1 赋值之后,我试图将那个variable1转换为String值.



after assigning a value to the variable1, i am trying to convert that variable1 to a String value.

String strvalue1 as String = variable1.ToString()



但是我的问题是,在.net 1.0版中,此 variable1 的值为123456789,但是在更高版本的.net frame work中,其值为123456789.00.我不明白为什么在更高版本的.net框架中此十进制值具有精度值?
在什么版本的.net Framework中,此精度值将用于十进制数据类型?

预先感谢.



But my problem is , this variable1 ,in .net version 1.0 is having the value 123456789 but in higher versions of .net frame work it is having the value 123456789.00 . I am not understanding why this decimal value is having precision value in higher version of .net frame work??
and in what versions of .net framework this precision value will come for decimal data type?

Thanks in advance.

推荐答案

从十进制类型的角度来看,这些值没有什么不同,只是字符串表示形式有所不同.如果将Decimal.ToString与格式相关的参数一起使用,则可以控制字符串格式的详细信息.请参阅:
http://msdn.microsoft.com/en-us/library/system.decimal. tostring.aspx [ ^ ].

IFormatProvider的参数与区域性相关,因为System.Globalization.CultureInfo实现IFormatProvider:
http://msdn.microsoft.com/en-us/library/system.globalization. cultureinfo.aspx [ ^ ].

要更好地控制任何数字类型的格式,请参见:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx [ ^ ].

—SA
Those values, from the standpoint of the decimal type, are not different, just the string representations are different. You can control the detail of string formatting if you use Decimal.ToString with format-related parameters. Please see:
http://msdn.microsoft.com/en-us/library/system.decimal.tostring.aspx[^].

The parameter of IFormatProvider is related to the culture, as System.Globalization.CultureInfo implements IFormatProvider:
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx[^].

For fine control over the formatting of any numeric types, please see:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

—SA


这篇关于转换为字符串值时,十进制数据类型值给出不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆