rji rji
rji rji

Reputation: 707

Round to highest .5 value in mysql

I am trying to round the value to highest 0.5 value.

For example if i execute

 select round(5.456);

Then I want to get the result as 5.5 and if I execute

select round(5.73434);

Then I want to get the result as 6.

That is if value is between 0 and 0.5 then it must be rounded to 0.5 and if the value is between 0.5 and 1 then it must be rounded to 1.

How can I do this? Thanks in advance

Upvotes: 4

Views: 3354

Answers (2)

frlan
frlan

Reputation: 7270

Might not the cleanest solution, but should do the trick:

select (CEILING(5.456 / 0.5) * 0.5)

CEILING is returning the higher value as shown in documentation.

Upvotes: 8

bIgBoY
bIgBoY

Reputation: 417

You need to pass the second parameter to the function round.

See documentation: Here

So, in your case, select round(5.456, 1); will give you the expected result.

Upvotes: -2

Related Questions