Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS expression to format two decimal places does not show zeros

I am using the following expression to format my value to show only two decimal points. Which Works fine if the value is not 0. However when the value is 0 it does not show 0.

eg. Expression used

=Format(Fields!CUL1.Value, "##.##") 

If CUL1.Value is 2.5670909 the value shown in the report 2.56 (this is brilliant!) If CUL1.Value is 0.006709 no value is shown (I would like it to show 0.00) If CUL1.Value is 0 no value is shown ( I would like to show 0)

Thanks.

like image 553
Abe Avatar asked Jan 17 '14 13:01

Abe


People also ask

How do you show two decimal places in SSRS?

Going to the Properties Window (F4) and find Number, then enter N2 as the format (or N0 is you want no decimal places) will generate a number in Excel. Just worked for me when I used cDbl as here: FormatNumber(Sum(cDbl(Fields!

How do I change decimal places in SSRS?

Properties to Format Number in SSRS To format a number in SSRS, Please select the Numbers Category from the available list. To remove those extra numbers from the decimal place, Select the Decimal Place property and change the value to 2.

How do you report to two decimal places?

Rounding to a certain number of decimal places 4.732 rounded to 2 decimal places would be 4.73 (because it is the nearest number to 2 decimal places). 4.737 rounded to 2 decimal places would be 4.74 (because it would be closer to 4.74).


2 Answers

If you want it as a string use:

=Format(Fields!CUL1.Value, "F2")

As a number use:

=FormatNumber(Fields!CUL1.Value, 2)

This will ensure it exports out to excel correctly as a number.

like image 52
Spegah Avatar answered Sep 22 '22 14:09

Spegah


You need to make sure that the first numeral to the right of the decimal point is always displayed. In custom format strings, # means display the number if it exists, and 0 means always display something, with 0 as the placeholder.

So in your case you will need something like:

=Format(Fields!CUL1.Value, "#,##0.##") 

This saying: display 2 DP if they exist, for the non-zero part always display the lowest part, and use , as the grouping separator.

This is how it looks on your data (I've added a large value as well for reference):

enter image description here

If you're not interested in separating thousands, millions, etc, just use #0.## as Paul-Jan suggested.

The standard docs for Custom Numeric Format Strings are your best reference here.

like image 45
Ian Preston Avatar answered Sep 21 '22 14:09

Ian Preston