c# - Database to DataGridView floating point error or non-trimmed trailing zeros -


my current project requires displaying numbers in datagridview column in windows forms front end. numbers can editted , sent database updated. values between 0 , 0.5. user's sake, wish trailing zeros removed, accuracy important value of 0.123456789 should stored full precision.

i had been using sql float store numbers, passing them doubles in c#. result in correct output, trialing zeros removed (e.g. 0.2, 0.123, 0.432105). problem values being inaccurately passed (e.g. 0.208 being returned 0.2080000002) due floating point error.

to solve this, changed using decimal data types in both database , front end. however, values displayed maximum number of defined decimal places (eg. 0.200000, 0.123000, 0.432105).

the possible solutions can see are:

  • removing trialing zeros decimal in datagridview.

    though,

    datagridview.columns[0].defaultcellstyle.format = "0.#" 

    doesn't appear work.

  • passing number accurately c# double, automatically display number in preferred format.

though, unable achieve either of these.

is able assist me problem?

private char[] _nozero = new char[] {'0'};

textbox1.text = l.fieldofdecimaltype.tostring().trimend(_nozero);


Comments