C
C#3mo ago
Graxonus

decimal celciusDiv not working and being used as 0 when casted as int

Trying to convert from farenheit to celcius and it just isn't working and I'm not sure why exactly. i can't multiply by a decimal variable it seems so have to cast as int. It then seems to result in celciusDiv becoming 0 instead of 5.0m/9.0m. It's a logic error as well so it won't even tell me why it isn't working.
No description
10 Replies
Angius
Angius3mo ago
You're rounding celciusDiv to an int An integer is... an integer It cannot have any decimal places
Graxonus
Graxonus3mo ago
Damn I just realised. Yeah I get you. In that case I'm not sure then how I would multiply by a decimal value
MODiX
MODiX3mo ago
Angius
REPL Result: Success
var dec = 5m / 9m;
Console.WriteLine($"Decimal is {dec}");
var i = (int)dec;
Console.WriteLine($"Rounded it's {i}");
var dec = 5m / 9m;
Console.WriteLine($"Decimal is {dec}");
var i = (int)dec;
Console.WriteLine($"Rounded it's {i}");
Console Output
Decimal is 0.5555555555555555555555555556
Rounded it's 0
Decimal is 0.5555555555555555555555555556
Rounded it's 0
Compile: 500.462ms | Execution: 37.185ms | React with ❌ to remove this embed.
Angius
Angius3mo ago
Make fahrenheit also a decimal
Graxonus
Graxonus3mo ago
Yeah I see what you mean, that's my mistake.
Angius
Angius3mo ago
And work only with decimals
Graxonus
Graxonus3mo ago
In general or just with this file?
Angius
Angius3mo ago
Well, wherever it makes sense Temperature, in general, can have decimal values So it should be represented as such If you're working with, dunno, warehouse management system, you can't have 1.8291 of a watermelon So integers make sense
Graxonus
Graxonus3mo ago
Yeah I get you that was just a silly thing on my part. I need more sleep or something 🤣 Thanks much, though.
Angius
Angius3mo ago
Anytime :Ok:
Want results from more Discord servers?
Add your server