Report Viewer - Setting the decimal places for a textbox value

孤者浪人 提交于 2019-12-18 09:01:57

问题


I'm using Report Viewer Control (rdlc) to generate reports. One of my columns have the value

=AVG(Fields!Reading.Value, "CellReading_Reading")

I'm getting the value with 10 or more decimal places. But i want to round it off to 3 decimal places. What is the expression for doing this?

Thank you. NLV


回答1:


FormatNumber(AVG(Fields!Reading.Value, "CellReading_Reading"),3)



回答2:


  1. Right-click the textbox
  2. Click the number
  3. Select number from the category
  4. Set Decimal Places to 0



回答3:


cdonner's answer was great and I incorporated it myself. If you have a slightly more complicated case as I did and you want to concatenate more than 1 field from more than 1 dataset you can do it like this...

=FormatNumber(Sum(Fields!Actual_Measurement.Value, "Measured_Result"), 1) & " (" & FormatNumber(First(Fields!Allowed_Min.Value, "Measured_Result_Details"), 1) & " - " & FormatNumber(First(Fields!Allowed_Max.Value, "Measured_Result_Details"), 1) & ")"

An example of what is displayed here would be ...

15.3 (12 - 16)

... If Actual_Measurement = 15.3, Allowed_Min = 12 and Allowed_Max = 16

In this case 1 entry in the "Measured_Result_Details" table relates to 1 or many entries in the "Measured_Result" table. Right clicking on the box and selecting "Expression", then looking in "Datasets" my two "Items" are "Measured_Result_Details" and "Measured_Result". This may be useful to anyone who has more than 1 dataset with fields from each dataset to be displayed in 1 Text Box!




回答4:


If you want without rounding off use Math.Truncate:

=Math.Truncate(1000*(AVG(Fields!Reading.Value, "CellReading_Reading")))/1000

Reference this and this post .

Hope helps.




回答5:


The simplest approach should be to just enter N3 in the format property of the textbox.

N stands for the number and C stands for the currency

Examples:

N0 format 123456.12 as 123,456

C2 format 1234.562 as $1,234.56

and so on ...



来源:https://stackoverflow.com/questions/2212512/report-viewer-setting-the-decimal-places-for-a-textbox-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!