C
C#2y ago
Wicked Cat

❔ Why is my decimal rounding?

I have to be missing something obvious but I would appreciate some help >.> with merchant.markup = 20, the decimal markup should be 1.2 but it's 1 '
decimal markup = (CurrentMerchant.Markup / 100) + 1;
decimal markup = (CurrentMerchant.Markup / 100) + 1;
11 Replies
Jimmacle
Jimmacle2y ago
what type is CurrentMerchant.Markup?
Wicked Cat
Wicked CatOP2y ago
int
Jimmacle
Jimmacle2y ago
yeah, int / int gives you an int you need to cast either the left or right side to a floating point type
Wicked Cat
Wicked CatOP2y ago
hmm okay i'll see what that is
Jimmacle
Jimmacle2y ago
simplest way is changing 100 to 100.0 which makes it a double instead of an int there are also suffixes you can add to number literals to make them a specific type, like:
100f = float
100d = double
100m = decimal
100f = float
100d = double
100m = decimal
Wicked Cat
Wicked CatOP2y ago
ahhhhh okay i remember this a little XD thank you so much
Cracker
Cracker2y ago
there are a lot of cats here
Jimmacle
Jimmacle2y ago
you say that like it's a problem
Cracker
Cracker2y ago
/mom-come-pick-me-up-there-are-cats-here
Mayor McCheese
For bare values it's best to supply the type by suffix, subtle bugs otherwise
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server