none
Convert.ToDecimal BUG! RRS feed

  • Question

  • Hello guys, here's my problem

    objRetorno.Quantidade = Convert.ToDecimal(view["quantidade"]);

    This is the problematic line... ObjRetorno is an object from ItemMesa class (which i've created) property Quantidade is from decimal type...

    Ok, now to the values that the debugger shows me:

    view["quantidade"]    "5.00"    object {string}

    this is the real value... (view is a DataRowView object) 5.00 which should be literal 5, right?

    BUT, after i convert it: objRetorno.Quantidade    500    decimal

    for some weird reason, the Convert.ToDecimal function is transforming "5.00" into 500, when it should be just 5! Anyone has the solution for this?
    Tuesday, August 26, 2008 4:13 PM

All replies

  • What are the regional settings on your PC? If you have period(.) as thousand separator, it would be converted to 500. If youy want to avopid any issues with separators during conversion and treat period as decimal separator, you could use next kind of code

     

    NumberFormatInfo provider = new NumberFormatInfo();

    provider.set_NumberDecimalSeparator(".");

    objRetorno.Quantidade = Convert.ToDecimal(view["quantidade"].ToString(), provider);

     

    Thursday, August 28, 2008 9:52 AM
    Moderator