❔ how to round numbers like real math

i want 3.3 to round to be 3 and 3.5 to be 4 and 3.8 to be 4 too. how do i do it?
11 Replies
Joschi
Joschi13mo ago
Math.Round Method (System)
Rounds a value to the nearest integer or to the specified number of fractional digits.
TJacken
TJacken13mo ago
Math.Ceil/Math.Floor
Joschi
Joschi13mo ago
Ceil will always round to ne next higher int so 2.1 -> 3. While Floor is the opposite 2.9 -> 2
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
i know but i dont know how to make it work how do i use it can you give me an example pls?
Joschi
Joschi13mo ago
var MyFloat = 1.2;
var RoundedNumber = Math.Round(MyFloat);
Console.WriteLine(RoundedNumber == 1);
var MyFloat = 1.2;
var RoundedNumber = Math.Round(MyFloat);
Console.WriteLine(RoundedNumber == 1);
TJacken
TJacken13mo ago
Yeah, you are right, I thought this was his problem.
Joschi
Joschi13mo ago
The docs I linked go in more detail on different rounding conventions, rounding errors and so on. So if you require high precision or some special amount of significant figures you should read them. They also have miultiple examples further down. Yeah, just wanted to add context to Ceil and Floor to prevent any misunderstandings.
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
איס thx its worked and i actually understand how to do it really helped me
Joschi
Joschi13mo ago
No problem. I think you can mark a question as complete with /close
Accord
Accord13mo 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