c# - Set 0 at Decimal place if no value found -


this question has answer here:

i need set “0” @ end of decimal place dynamically if less integer number found after decimal place.

suppose have value: “535.8” need set “535.800” have following code:

string cost = "535.8"; string decplace = "3";  decimal price = decimal.round(convert.todecimal(cost), convert.toint32(decplace)); console.writeline(price); console.readline(); 

unable 535.800.

how can achieve this?

you can convert price string , show upto 3 decimal places 0's @ end.

            string cost = "535.8";             string decplace = "3";              decimal price = decimal.round(convert.todecimal(cost), convert.toint32(decplace));             //string.format("{0:n2}", price);             console.writeline(string.format("{0:n3}", price)); 

Comments