本文介绍了C#小数类型划分的精度是单声道有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

decimal d1 = 4.0m;
decimal d2 = 40.0m;
decimal d = d1 / d2;
string repr = d.ToString();

在Windows中,我得到0.1的再版。在Mono(Xamarin的Android),我得到0.1000000000000000000000000000左右。是什么赋予了?另外,我见过的建议通过1.0000000000000000000000000000米分来摆脱不必要的尾随零的。这并不对Xamarin的Android无论是工作

On Windows, I get "0.1" for repr. On Mono (Xamarin Android), I get "0.1000000000000000000000000000" or so. What gives? Also, I've seen recommendations to divide by 1.0000000000000000000000000000m to get rid of unwanted trailing zeroes. That doesn't work either on Xamarin Android.

已知的bug?上或技术上不是一个错误 - 这是允许符合标准的一致性

Known bug? Or technically not a bug - is this allowed in conformance with the standard?

要摆脱零,我的价值转换为字符串,删除尾随零呢?从字符串,并将其转换回为十进制。这是非常弱的。另外,我的解决方案不会产生我想确切的结果。我宁愿离开后是适当显著,而不是删除所有尾随零零。

To get rid of the zeroes, I'm converting the value to a string, removing trailing zeroes from the string, and converting it back to a decimal. It's pretty weak. Also, my solution doesn't produce the exact results I'd want. I'd prefer to leave trailing zeroes that are appropriately significant, rather than removing all trailing zeroes.

推荐答案

也许这是值得注,这个错误已得到修复,由米格尔奥德伊卡萨说:

Maybe it's worth a note, that this bug has been fixed, as stated by Miguel de Icaza: https://bugzilla.novell.com/show_bug.cgi?id=655780#c2

这篇关于C#小数类型划分的精度是单声道有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:30