format - Rounding and formatting the nullable decimal in c# -


im using below code round decimal 2 decimal places.

  decimal? rtime = rtime.hasvalue ? decimal.round(rtime.value, 2) : 0; 

but converting numberlike 512->512.00 not working..how do that?

decimal.round rounds value of decimal. example 512.123 512.12.

what want string representation. need format value instead of rounding. can use tostring() that:

decimal? rtime = rtime.hasvalue ? decimal.round(rtime.value, 2) : 0; string rtimeasstring = rtime.value.tostring("0.00"); 

or string.format or string interpolation this:

string rtimeasstring = string.format("{0:0.00}", rtime); string rtimeasstring = $"{rtime:0.00}" 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -