我正在尝试处理值更改,以便进行计算
private void supplierDiscountPercetangeSpinEdit_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
decimal price, percentage, calculatedPrice;
price = (decimal)supplierPriceSpinEdit.EditValue;
percentage = Convert.ToDecimal(e.NewValue); // breakpoint 1
calculatedPrice = Popust.Izracunaj(price, percentage); // breakpoint 2
supplierPriceWithDiscountSpinEdit.EditValue = calculatedPrice;
}
在断点 1 e.NewValue
处是 object {string} "1.00"
在断点 2 处百分比
为object {decimal} 100
并且必须是1.00M
如何将 e.NewValue
转换为十进制?
最佳答案
您应该使用CultureInfo
:在您当前的文化中'.'是千分隔符,而不是小数 一;这就是为什么
1.00 -> 100 // <- thousand separator '.' removed
尝试这样说
Convert.ToDecimal(e.NewValue, CultureInfo.InvariantCulture);
关于c# - 将 e.NewValue 转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21426371/