2014-01-29 60 views
2

我想句柄值改變,所以我可以使計算轉換e.NewValue爲十進制

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.NewValueobject {string} "1.00"

在斷點2 percentageobject {decimal} 100

,它必須是1.00M

如何將e.NewValue轉換爲deci發作?

+0

已經嘗試過解析,但它只是忽略小數大關。 – Carlo

回答

5

您應該使用CultureInfo:在您當前的文化中'。'分隔符,不是小數點一;這就是爲什麼

1.00 -> 100 // <- thousand separator '.' removed 

嘗試把它像

Convert.ToDecimal(e.NewValue, CultureInfo.InvariantCulture);