Rules for counting with parentheses C# -
this question has answer here:
- c# simple divide problem 9 answers
this mabey dumb question try count discount on price this:
newallavaror.pris = system.convert.todouble( (1 - (clientkampanj.visakampanj(vara.produktnamn) / 100)) * vara.pris ).tostring();
it in reality (1-(20/100)*7.99), output 7.99 should 6,392..becuse orginal price 7.99... have tried move parentheses 1 then..
in wich order c# go thru parentheses, becuse should work right??
i'm pretty sure doing integer division here:
(clientkampanj.visakampanj(vara.produktnamn) / 100)
so if have 20/100, result in 0 instead of expected 0.2 reminder truncated.
you need convert double, 1 of operands:
(clientkampanj.visakampanj(vara.produktnamn) / 100.0)
since @scott pointed out other variables of type decimal
, need convert 1 of operands type instead:
(clientkampanj.visakampanj(vara.produktnamn) / 100.0m)
Comments
Post a Comment