在C#中,我们可以使用精确度将十进制值作为小数点后的2个零。 [英] In C# can we strore Decimal value with precison as 2 zeros after decimal point.

查看:78
本文介绍了在C#中,我们可以使用精确度将十进制值作为小数点后的2个零。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我们在XSD的帮助下通过C#代码创建XML文件。



这里一个字段是十进制,字段格式是XXXX.XX(9999.00)



现在如果十进制后的数字不是零,那么我们可以实现这个目标但是如果一个值为零那么它就会四舍五入。



例如: - 如果一个值是9999.96那么我们能够正确存储但是值是9999.00然后它被转换至9999



可以存储为9999.00



请提供建议。



谢谢

Hi All,

We are creating XML file through C# code with the help of XSD.

Here one field is decimal and field format is XXXX.XX(9999.00)

Now if digits after decimal is other than zero then we are able to achieve this but if a value is zero then it's getting rounded.

e.g:- if a value is 9999.96 then we are able to store correctly if but value is 9999.00 then its getting converted to 9999

Is it possible to store as 9999.00

Please provide me suggestions.

Thanks

推荐答案

在.NET(C#)中,decimal是128位数字数据类型。类型本身,与所有其他类型一样,没有定义小数点后可能有或没有多少有效数字...

首先你必须明白这里没有数学(数学)差异在999和999.00之间,所以接收一个或另一个应该没有任何问题...但是如果你谈论格式化用于显示目的,那么你应该格式化输出...

In .NET (C#) decimal is a 128 bit numeric data type. The type itself, like with all the other types not defines how much significant digits you may or may not have after the decimal point...
First you must understand that here is no numerical (mathematical) difference between 999 and 999.00, so there should not be any problem receiving one or the another...However if you talking about a formatting for display purposes, than you should format the output...
value.ToString("F2");



其中F表示固定点,2表示小数点后的位数...

http://msdn.microsoft.com/en-us/library/ dwhawy9k(v = vs.110).aspx [ ^ ]


可以传输任何数值使用 ToString(格式在这里)格式化字符串,在您的情况下,它将是 ToString(#。00)
Any numeric value can be converted to a formatted string with ToString("format here") and in your case it would be ToString("#.00").


嗨感谢回复...但我不想在字符串中转换相同的内容..只需要维持十进制数。所以转换为String对我没有帮助,因为XSD中的字段类型是十进制的。
Hi Thanks for Reply ... but I don't want to convert same in String.. need to maintain in decimal only. So coverting to String will not help me as field type in XSD is decimal.


这篇关于在C#中,我们可以使用精确度将十进制值作为小数点后的2个零。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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