本文介绍了如何处理小数点值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有点混淆,如何处理小数点值,因为我必须接收像0.1,0.012334839493,0.00193999329,1,2这样的值。当我从数据库中获取此值并且我必须将此值发送到4位数时,可能使用超过4位数的值,但是当值小于4位(如0.1,1,2)时会出现错误。它无法处理这个值,有没有办法处理这种情况。
这里代码,
I am little bit confuse here, that how to handle decimal point value as i have to receive values like 0.1 , 0.012334839493 , 0.00193999329 , 1 , 2 . when i get this values from database and i have to sent this values upto 4 digits , it is possible with values more than 4 digits but when value less than 4 digit (like 0.1 , 1 , 2 ) comes it gives error. it cannot handle that value , is there any way to handle this situation.
here the code ,
foreach (DataRow row in table.Rows)
{
string stock = row["stocksum_id"].ToString();
string product = row["prod_name"].ToString();
string packing = row["conversion_factor"].ToString();
string mfg = row["manufacturer_id"].ToString();
string batch = row["batchno"].ToString();
string expiry = row["expiry_date"].ToString().Substring(0, 10);
string mrp = row["mrp"].ToString();
string totq = row["current_stock"].ToString();
string[] mrpvalue = row["purchase_price"].ToString().Split('.');
string barcode = row["scan_code"].ToString();
string prodGrade = row["prod_grade"].ToString();
if (totq.Contains("."))
{
totq = totq.Substring(0, 3);
}
当totq收到0.1或1的值时会出错。
谢谢!
when totq receive value 0.1 or 1 it gives error.
Thanks!
推荐答案
if (totq.Contains(".") && totq.Length>3)
{
totq = totq.Substring(0,3);
}
这篇关于如何处理小数点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!