简体   繁体   中英

How to format a number with an expression in SSRS based on a value?

I have fields called price and minIncrement in my DataSet for my SSRS 2012 report. I want to format the price using an expression based on the minIncrement field. For example if the price is 94.95000 and the minIncrement is 0.01 , then I want the price displayed on the report as 94.95 . If the price is 12345.000000 and the minIncrement is 1 , then display the price as 12345 .

Is there a way to do that? Possible minIncrement values are

0.000100
0.010000
0.100000
0.250000
1.000000

You could create an expression, something like:

=Format(
    Fields!Price.Value, 
    Switch(
        Fields!MinIncrement.Value = 0.000100, "0.0000",
        Fields!MinIncrement.Value = 0.010000, "0.00",
        Fields!MinIncrement.Value = 0.100000, "0.0"
    )
)

Just expand the Switch statement with the other possible values for MinIncrement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM