Pregunta

I'm converting string value to double and sending it to database. Displaying 6 decimal places. Here is the code

strUpdate = "UPDATE tbPrice SET dblPrice = " 
    + Convert.ToDouble(txtPrice.Text.Trim())
    + ",chrCity  = '" + txCity.Text.Trim()
    + "' WHERE pk_lngID = " + txtID.Text.Trim();

Here txtPrice value is 1.23456789, but when it is updated into database its value changed to 1.2345679. why is it rounding off the value. I need to get 1.234567 (user entered value truncated upto 6 decimal places.

¿Fue útil?

Solución

Summarizing my comments as they ended up being the accepted answer:

okay, in Access, you can set your field type to Number. then set the number of decimal places for what you want. If you use less than say, 6, it will round the number to the 5th.

I think the DB is causing the rounding, not your C#. I don't there there IS a way to set a specific type "double" in Access. Edit: Double is there, but the bottom line is the number of decimal places need to be set correctly.

Please see comments for full conversation.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top