简体   繁体   English

十进制后的数字替换为0

[英]substitute the number after decimal with 0

How do I replace the decimal part of currency with 0's Here's my cuurency: 166.7 This is to be formatted as 000000016670 如何用0代替货币的小数部分,这是我的货币:166.7这将被格式化为000000016670

The length of this field is 12. 该字段的长度是12。

s.padright(12,0); This is will the second part I believe. 这是我相信的第二部分。 The first part will involve replace the number after the decimal with 000.. 第一部分将小数点后的数字替换为000。

Thanks 谢谢

You can multiply by 100 then format the number. 您可以乘以100,然后格式化数字。

var num = 166.7;
var numString = (num * 100).ToString("000000000000");

Multiplying by 100 turns 166.7 to 16670. Next you need to pad the left part of the number, which is what the ToString does. 乘以100可将166.7乘以16670。接下来,您需要填充数字的左侧部分,这就是ToString的作用。 Each 0 represents a digit. 每个0代表一个数字。 It means, write the number that belongs to that digit, and if no number is present print 0. 这意味着写出属于该数字的数字,如果没有数字,则打印0。

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

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