[英]Decimal into string conversion shows different decimal values in different windows systems
我有一個 c# 代碼在 .net 框架 2.0 中運行,當將十進制轉換為要在文件中打印的字符串時,會在不同的 Windows 操作系統中產生不同的輸出。
我已經檢查了兩個系統區域設置是否完全相同,相同的語言,相同的數字格式等。
我的代碼看起來像這樣
object o = dr.GetValue(dr.GetOrdinal(cCol.ColumnName));
string value = Convert.ToString(o);
它正在從數據庫中獲取一個值,並且 object 是十進制類型(o.GetType()==typeof(Decimal) 評估為真)
The problem is that when this program runs in .net Framework 2.0 but in a windows 2000 server the output is not the same as running in .net framework 2.0 in windows 10.
例如對於值 2016
Windows 2000 output:“2016”
Windows 10 output:“2016.00”
我試過以下
string value = ((Decimal)o).ToString("0.##"));
然后 output 與 2016 的值相同。但是,這里是棘手的地方,如果值是 2016.6,則使用這種新方法的 output 是:
Windows 2000 output:“2016.60”
Windows 10 output:“2016.6”
因此,在兩個系統中,我無法將它與 output 相同。
問題的根源是什么? 有什么辦法可以讓我在 windows 10 中獲得與 Windows 2000 相同的 output 嗎?
謝謝
回答我自己的問題時,我發現問題在於,在 windows 2000 中,db 驅動程序有時將值返回為 Int,而在 Windows 中,有時將值返回為十進制。 所以問題出在數據庫驅動程序而不是 .net 框架中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.