简体   繁体   English

如何从字符串中删除小数部分?

[英]How remove decimal part from string?

how to trim decimal part in given string of a decimal value in C#. 如何在C#中修剪给定的十进制值字符串中的小数部分。 im getting 20472.060 desired o/p - 20472 即时通讯获得20472.060所需的输出/输出-20472

decimal totalamountWithTaxes = pri + result1 + result2 ;          
string totalAmountPlusTaxes = totalamountWithTaxes.ToString();

You can simply do it like this: 您可以像这样简单地做到这一点:

int number = (int) totalAmountPlusTaxes;

or 要么

string totalAmountPlusTaxes = String.Format("{0:C0}",totalamountWithTaxes);

是的,上面的示例是正确的,我也建议您访问: String.Format方法-MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM