12,451,227 members (52,397 online)
Rate this:
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.

Regards.
Posted 2-Apr-13 6:56am
ThePhantomUpvoter 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"

Rate this:

## Solution 1

Hi,

Use the Convert.ToSingle method[^] instead of the `Convert.ToInt32` method:
```float v_tax = Convert.ToSingle(ds.Tables[0].Rows[i]["tax"]);
```
Rate this:

## Solution 2

Precision is the main difference between double and float. Decimal has more precision that float.
Try using float.

Top Experts
Last 24hrsThis month
 ppolymorphe 199 OriginalGriff 115 Richard MacCutchan 70 Afzaal Ahmad Zeeshan 60 Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ) 50
 OriginalGriff 6,103 ppolymorphe 3,600 Karthik Bangalore 3,530 Maciej Los 3,005 Richard Deeming 2,830

Web02 | 2.8.160826.1 | Last Updated 2 Apr 2013