Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi everyone,
I have a Razor email template, and I would like to do simple mathematics in this code, e.g. amount1 + amount2, or amount1 * amount2.
I tried this:
@{ string am1 = (string)Model.DynamicFields.amount1; string am2 = (string)Model.DynamicFields.amount2; int a1 = am1.AsInt(); int a2 = am2.AsInt(); var sum = (a1+a2); var product = (a1*a2); var division = (a1/a2); <H1>@sum</H1> <H1>@product</H1> <H1>@division</H1> }
This basically works, however only for integers. How would I do this with decimals?
Best, Simeon
You would need to convert the string to a decimal
https://learn.microsoft.com/en-us/dotnet/api/system.convert.todecimal?view=net-7.0
Hi Huw,
Thank you! I got it working with
@{ string am1 = (string)Model.DynamicFields.amount1; string am2 = (string)Model.DynamicFields.amount2; var a1 = Convert.ToDecimal(am1); var a2 = Convert.ToDecimal(am2); var sum = (a1+a2); var product = (a1*a2); var division = (a1/a2); <H1>@sum</H1> <H1>@product</H1> <H1>@division</H1> }
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Do decimal mathematics in Razor email template
Hi everyone,
I have a Razor email template, and I would like to do simple mathematics in this code, e.g. amount1 + amount2, or amount1 * amount2.
I tried this:
This basically works, however only for integers. How would I do this with decimals?
Best, Simeon
You would need to convert the string to a decimal
https://learn.microsoft.com/en-us/dotnet/api/system.convert.todecimal?view=net-7.0
Hi Huw,
Thank you! I got it working with
Best, Simeon
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.