Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Emmanuelle__Bustos
Partner - Specialist
Partner - Specialist

Round() function

Hi I need to use the Round() function in order to round the data whit this logic:

If the data has any decimal values it is rounded to .5 or next integer, if the data has no decimal values it remains as it is (integer).

is this possible: ie.

1.2  --> 1.5

1.6 -->  2

4    -->  4

hope you can help me.

1 Solution

Accepted Solutions
sunny_talwar

Might be easier to use Frac function here

If(Frac(Number) > 0, Ceil(Number, 0.5), Number)

or just this

Ceil(Number, 0.5) as Number

View solution in original post

5 Replies
vvira1316
Specialist II
Specialist II

Hi,

Rounding2.PNG

Decimal part

=If(IsNull(SubField(RoundingNumbers, '.', 2)), 0, SubField(RoundingNumbers, '.', 2))

Rounded Number

=If(IsNull(SubField(RoundingNumbers, '.', 2)), RoundingNumbers,
If(SubField(RoundingNumbers, '.', 2) <=5, Num#(SubField(RoundingNumbers, '.', 1) & '.' & '5'), Num#(SubField(RoundingNumbers, '.', 1) +1)))

BR,

Vijay

sunny_talwar

Might be easier to use Frac function here

If(Frac(Number) > 0, Ceil(Number, 0.5), Number)

or just this

Ceil(Number, 0.5) as Number

sunny_talwar

Check this out

Table:

LOAD Number,

If(Frac(Number) > 0, Ceil(Number, 0.5), Number) as Test1,

Ceil(Number, 0.5) as Test2;

LOAD * INLINE [

    Number

    1.2

    1.6

    4

];

Capture.PNG

Emmanuelle__Bustos
Partner - Specialist
Partner - Specialist
Author

Thank you so much for your answer but I see that the @Sunny Talwar is a little more practice way and it solve my need.

Best regards!

Emmanuelle__Bustos
Partner - Specialist
Partner - Specialist
Author

Thank you very much I see the Ceil() function is what I was looking for.

Best Regards!