Subject Re: [firebird-support] Round function
Author Paul Vinkenoog
Hi Luis,

> Is anyway to round a value to + - 0.05?
>
> For example:
>
> For the values value 1.732288 and 0.9324. After the round, i expect the values of 1.75 and 0.95
>
> For the values value 1.7131 and 0.412324. After the round, i expect the values of 1.70 and 0.4

I'd say:

1: Multiply the argument by 2
2: Use ROUND() to round to the nearest multiple of 0.1
3: Divide the result by 2

You can condense this into one expression: ROUND(2*arg, 1) / 2.0

You may have to cast the result to the required decimal or numeric type.

See http://www.firebirdsql.org/refdocs/langrefupd21-intfunc-round.html,
including the note about the scale of the result.


Hope this helps,
Paul Vinkenoog


PS:
You need Firebird 2.1 or higher for this. But you can work out a similar
solution with the round() UDF in earlier versions.