❔ Attempting to multiply a number by a decimal, keeps getting 0
Hello, I am attempting to multiply a number by .5, and whenever I do the end result is 0.
10 Replies
There's nothing wrong with it when it is a single digit number, but whenever I change Discount to any type of decimal it just goes to 0
What is the type of Discount?
Int
Should the variable be set to double?
Well, an int can't describe numbers like 0.5.
Ah
What should I set it to, if anything?
If you don't care about a bit of rounding error, float. Otherwise decimal
Thanks man, I really appreciate it
I'm new to coding in general lol, thanks again
try using casting to decimal
Ex: decimal number = (decimal)integer * 0.8m;
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.