❔ 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
You are looking for
Math.Round()
: https://learn.microsoft.com/en-us/dotnet/api/system.math.round?view=net-7.0Math.Round Method (System)
Rounds a value to the nearest integer or to the specified number of fractional digits.
Math.Ceil/Math.Floor
Ceil will always round to ne next higher int so 2.1 -> 3. While Floor is the opposite 2.9 -> 2
i know but i dont know how to make it work
how do i use it
can you give me an example
pls?
Yeah, you are right, I thought this was his problem.
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.
איס
thx
its worked
and i actually understand how to do it
really helped me
No problem.
I think you can mark a question as complete with /close
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.