Skip to content
Advertisement

Round decimal number to .5 when decimal is below .5 – PHP

Is there any way to round up decimal number to .5 if the decimal value is below or equal to .5 instead of rounding up to whole number?

Ex:

JavaScript

but when the decimal value is greater than .5 round the number up

JavaScript

Advertisement

Answer

If x is your variable do Ceil($x * 2) / 2 Which will round your number to the nearest whole number or 0.5

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement