This is a migrated thread and some comments may be shown as answers.

Currency and Floor/Ceiling

1 Answer 339 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 19 Mar 2020, 04:43 PM

I am trying to show a customer the total amount remaining after a 50% deposit plus whatever extra payments have been made.

The expression I'm using is:

 

= Floor(Fields.SubTotal - (Fields.SubTotal * .5) - IsNull(Fields.Payments, 0))

The field format is currency with two decimal places to account for dollars and cents. I assumed that Floor() would account for that fact and round every number down to the nearest penny. $1,350.375 would in fact become $1,350.37. Instead, Floor() is rounding to the nearest dollar and the value I get is $1,350.00. Does Floor/Ceiling take into account the format I want my number to be in? If not, why not? That seems intuitive to me but apparently it isn't to the developers who worked on those specific functions.

I end up with one field showing the deposit (50%): 1,350.38

and another field with the balance owing: 1,350.38

I realized that in the formula above, the portion (Fields.SubTotal * .5) doesn't convert this value to two decimal places (it remains 1,350.375) and so it subtracts 1,350.375 from the Subtotal (2,700.75), returning the value 1,350.375 which it then rounds up to 1,350.38 But when you add the Balance Owing to the original deposit, I always get a value that is one penny higher than the original subtotal.

Is there a way to do this correctly in the Standalone Reporter?

 

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 24 Mar 2020, 09:03 AM

Hello John,

The formatting is applied to the value after the expression is evaluated, the expression engine does not take into account the Format options of the report item. If the formatting needs to be applied during the expression evaluation you can use Format(format, value) and FormatWithCulture(cultureName, format, args) built-in functions.

To round the number to a specific number of fractional digits, you can also use Round(number, digits) built-in function.

 

Regards,
Katia
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Report Designer (standalone)
Asked by
John
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or