I am doing some arithmetic calculation inside Razor view as below
decimal n = Convert.ToDecimal(Model.np_claim_dtls[i].PROV_PRICE);
decimal d = Convert.ToDecimal(Model.np_claim_dtls[i].DISCOUNT_AMOUNT);
<text> @(n-d) </text>
its giving me result as below
923.0340000000000
expected result is
923.03
How can i use rounding inside razor? Please help
You can round off the values like
decimal d = 100.1255M;
string s1 = d.ToString( "#.##" ); // 100.13
string s2 = d.ToString( "0.00" ); // 100.13
This can also be done in the controller rather than view. Exposing computations in view is not recommended
This should be working :
decimal n = Convert.ToDecimal(Model.np_claim_dtls[i].PROV_PRICE);
decimal d = Convert.ToDecimal(Model.np_claim_dtls[i].DISCOUNT_AMOUNT);
<text> @(Math.Round(n - d, 2)) </text>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With