Round up with criteria

Hi guys, do anyone have idea on how to round up the number as listed below:
If the string is 28.1 then the output should be 28.5
28.1 → 28.5
28.2 → 28.5
28.3 → 28.5
28.4 → 28.5
28.5 → 28.5
28.6 → 29.0
28.7 → 29.0
28.8 → 29.0
28.9 → 29.0
Anyone have any idea to cater this?

Hi @Serran_Neru,

Math.Round(value)

Regards,
Arivu

1 Like

Hi @arivu96

Using that syntax will give output as below, which is not as desired
28.1 → 28
28.2 → 28
28.3 → 28
28.4 → 28
28.5 → 28
28.6 → 29
28.7 → 29
28.8 → 29
28.9 → 29

Any other way that can cater as desired?

Hi @Serran_Neru,
Try this

(Math.Ceiling(2 * value)) / 2

Regards,
Arivu

1 Like

That perfectly work, thanks arivu :slight_smile:

Hi @arivu96, last time you helped me on a specific round up criteria (Round up with criteria - #4 by arivu96)

However, I’m having another requirement to round up as below.

We have to use 2nd decimal to roundup the first decimal. Example shown below?

Is there any code to achieve this? Really hope you could help on this.

Weight Round up to first decimal
3.00 3.0
3.01 3.1
3.02 3.1
3.03 3.1
3.04 3.1
3.05 3.1
3.06 3.1
3.07 3.1
3.08 3.1
3.09 3.1
3.10 3.1
3.11 3.2
3.12 3.2
3.13 3.2
3.14 3.2
3.15 3.2
3.2 3.2
3.6 3.6

Hi,
Try below code
Math.Round(1.46,1,MidpointRounding.AwayFromZero)

Hi @arivu96, yes it works for those second decimal which is more than 5. Those less then 5 is not adding 1 to the first decimal :frowning:

Is there any other way?

image