[英]What's the proper way to save percentage value from flat file to database table without infinite floating values?
從平面文件導入百分比值到數據庫時。 假設百分比值(來自平面文件)為字符串“ 91.92”。 此值分配給c#“ float”變量,然后將其保存為“ float”列到數據庫表中。
我的問題是字符串值是“ 91.92”,數據庫數據最終顯示為“ 91.9199981689453”。 我不希望舍入或無限值(或指數值)。
string ftpDataInterestRate = "91.92"; //This is from FTP file... (Can't write ftp script here)...
float dataInterestRate = float.parse(ftpDataInterestRate); //This is assigning the value to variable from ftp file for file reader components.
sql = " INSERT INTO Foo1 ";
sql += " (InterestRate) ";
sql += " VALUES ";
sql += " @InterestRate ";
dbCommand.CommentText = sql;
dbCommand.Parameters.AddWithValues("@InterestRate", dataInterestRate);
dbCommand.ExecuteNonQuery();
[MS-SQL Table]
[InterestRate] [float] NOT NULL
有沒有更簡單的方法來使數據庫將值顯示為“ 91.92”? 同樣,如果該值為“ 83.2”,則將其另存為“ 83.2”。 同樣,如果該值為“ 76”,則將其另存為“ 76”。
謝謝..
將其存儲為小數。 浮點數和雙打總是近似值,我想你並不是真的想要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.