how do i round off decimal values ?
Example :
decimal Value = " 19500.98"
i need to display this value to textbox with rounded off like " 19501 "
if decimal value = " 19500.43"
then
value = " 19500 "
Look at Math.Round(decimal)
or the overload which takes a MidpointRounding
argument .
Of course, you'll need to parse and format the value to get it from/to text. If this is input entered by the user, you should probably use decimal.TryParse
, using the return value to determine whether or not the input was valid.
string text = "19500.55";
decimal value;
if (decimal.TryParse(text, out value))
{
value = Math.Round(value);
text = value.ToString();
// Do something with the new text value
}
else
{
// Tell the user their input is invalid
}
Math.Round( 值, 0 )
Try this...
var someValue=123123.234324243m;
var strValue=someValue.ToString("#");
Total = Math.Ceiling(value)
如果对你有帮助就回复
string text = "19500.55";
text =(decimal.TryParse(text, out value))? (Math.Round(decimal.Parse(text))).ToString():"Invalid input";
d = decimal.Round(d);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.