Rules for counting with parentheses C# -


this question has answer here:

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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -