fdkgfosfskjdlsjdlkfsf
fdkgfosfskjdlsjdlkfsf

Reputation: 3303

Strip decimals in SSRS expression without rounding

In my report I'm trying to remove the decimals without rounding. I'll be using this to set the minimum value in the vertical axis of the area chart.

So I tried =Format(98.56, "N0"), but this returns 99, which is incorrect. It should return 98.

I've been searching specifically for SSRS, but most of the results are for tsql.

My question: How can I remov decimals in SSRS without rounding?

Thanks

Upvotes: 2

Views: 10700

Answers (3)

martin
martin

Reputation: 11

I know the question is quite old, but as I ended up here having the same question I would like to share my answer:

While FLOOR and CEILING are fine if you take extra measures to handle numbers <0 or know they are always >=0, the easiest way to simply strip off the decimals is to use

=Fix(Fields!Number.Value)

FIX only returns the integer part of a number, without any rounding or transformation. For negative numbers Int rounds up.

Source: Examples for Fix, Floor and Ceiling

Source: Difference between Int and Fix

Upvotes: 1

Christopher M. Brown
Christopher M. Brown

Reputation: 2210

Try using "Floor". It effective rounds down to the nearest integer. You'll find this under the Math functions.

=Floor(Fields!Number.Value)

Note, there's also a Floor function in Transact-SQL that works the same way in case you need to do some of the processing in your SQL script.

Update based on request in comments If you wanted to achieve the same result after the decimal point, all you need is a little algebra.

=Floor((Fields!Number.Value*10))/10

That should turn 99.46 into 99.4. Given that it shaves off the remainder, you could then tack on any additional zeroes you wanted.

Upvotes: 5

fdkgfosfskjdlsjdlkfsf
fdkgfosfskjdlsjdlkfsf

Reputation: 3303

I ended up converting to Int. The following expression in SSRS returns 98:

=Int(98.56)

Upvotes: 1

Related Questions