![]() |
|
problem with float numbers - Printable Version +- LCKB (https://lckb.dev/forum) +-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109) +--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196) +---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192) +---- Thread: problem with float numbers (/showthread.php?tid=2289) |
- soryjero - 08-08-2013 hello, i am updating db but it doesnt update correctly. i have a datagridview where i get values from db. 2 when i try to update it to db, in db only appears the int part of the number in the col Probability. i use this record to update: record = "INSERT INTO t_moonstone_reward (a_type, a_index, a_giftindex, a_giftcount, a_giftprob, a_giftflag) VALUES ( 2545, " + dataGridView1[0, i].Value + ", " + dataGridView1[1, i].Value + ", " + dataGridView1[2, i].Value + ", " + dataGridView1[3, i].Value + ", " + dataGridView1[4, i].Value + " ) ON DUPLICATE KEY UPDATE a_index = " + dataGridView1[0, i].Value + ", a_giftindex = " + dataGridView1[1, i].Value + ", a_giftcount = " + dataGridView1[2, i].Value + ", a_giftprob = " + Convert.ToDecimal(dataGridView1[3, i].Value) + ", a_giftflag = " + dataGridView1[4, i].Value + " ;"; and when i run this sentence, update well but field a_giftprob updates bad because it only updates int part of the number (in this case number is 0,5 and only appears 0). could anyone help me? thanks in advance. - someone - 08-08-2013 Convert.ToDecimal(dataGridView1[3, i].Value) You can simply usa dataGridView1[3, i].Value.ToString(), since its in that format(be sure it contains. and not ,), check the table if the column is FLOAT or DOUBLE. - soryjero - 08-08-2013 Convert.ToDecimal(dataGridView1[3, i].Value) You can simply usa dataGridView1[3, i].Value.ToString(), since its in that format(be sure it contains. and not ,), check the table if the column is FLOAT or DOUBLE. table column is float and my value contains , do i need to use that sentence or i need another? - HateMe - 08-09-2013 you also can use the "Replace" function dataGridView1[3, i].Value.ToString().Replace( ",", "." ); - soryjero - 08-09-2013 you also can use the "Replace" function dataGridView1[3, i].Value.ToString().Replace( ",", "." ); yes, but in db also appear , and if i try to put . i cant - soryjero - 08-09-2013 Fixed with this: you also can use the "Replace" function dataGridView1[3, i].Value.ToString().Replace( ",", "." ); in db appears , but if i write . also works and in db appears like , so its ok. thanks all. |