Reputation: 43
How do I divide a column that I convert to an int
and get the dollar amount?
For example, if thisAmount=19
, then the output should be .19
. With the current code below, it outputs 0.00
@((((int)row["thisAmount"])/100).ToString("c"))
Upvotes: 1
Views: 185
Reputation: 4913
When you divide int1
per int2
, like int1/int2
. you should cast int2
to double, and the result will be casted too. so it's become like int1/(double)int2
.
Change your code to :
@((((int)row["thisAmount"])/(double)100).ToString("c"))
Or use decimal.Divide
function :
@(decimal.Divide((int)row["thisAmount"], 100).ToString("c"))
I hope you find this helpful.
Upvotes: 5