Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I would like to know what exactly to use in my following code:


float v_tax = Convert.ToInt32(ds.Tables[0].Rows[i]["tax"]);


The 'tax' is a float datatype holding 12.55 as data.
During run time the variable v_tax is having value as 13 instead of 12.55.

Can anyone please guide me.
Regards.
Posted
Comments
[no name] 2-Apr-13 13:05pm    
"value as 13 instead of 12.55" that is because you are converting the value to an integer, "Convert.ToInt32"

Hi,

Use the Convert.ToSingle method[^] instead of the Convert.ToInt32 method:
C#
float v_tax = Convert.ToSingle(ds.Tables[0].Rows[i]["tax"]);
 
Share this answer
 
Precision is the main difference between double and float. Decimal has more precision that float.
Try using float.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900