如何从double值中删除小数点 [英] How to remove decimal point from double value

查看:204
本文介绍了如何从double值中删除小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个数字格式如下:



15.2564

4.5268

235.9985

0.5656

78.3211



我想得到的是:



0152564

0045268

2359985

0005656

0783211



从double值中删除小数点并添加以下内容的最佳方法是:

1. 如果值在小数点前有三个数字(示例235.9985将为2359985),则在值前面没有零

2. 一个零在前面值如果值在小数点前有两个数字(示例15.2564将 0 152564)

3. 两个零在值前面该值在小数点前有一个数字(例如4.5268将 00 45268)



我尝试了什么:



在意义上我正在寻找类似的例子。

我找到了与格式相关的第二部分的解决方案。

Hello to all,
I have a numbers in the format like:

15.2564
4.5268
235.9985
0.5656
78.3211

What I would like to get is:

0152564
0045268
2359985
0005656
0783211

What is the best way to remove the decimal point from double values and to add:
1.no zeros in front of the value if the value has three numbers before decimal point (example 235.9985 will be 2359985)
2.one zero in front of the value if the value has two numbers before decimal point (example 15.2564 will be 0152564)
3. two zeros in front of the value if the value has one number before decimal point (example 4.5268 will be 0045268)

What I have tried:

In the meaning time I am searching for the similar example.
I have found a solution for the second part related to format.

Dim dblValue As Double = 15.2564
Dim fmt As String = "000.####"
Console.WriteLine(dblValue.ToString(fmt))

推荐答案

试试这个

Try this
decimal decNum = 0.5656M;
var strArr = decNum.ToString().Split('.').ToArray();
string finalString = strArr[0].PadLeft(3, '0') + strArr[1];


尝试乘以10000以移除小数点。
try to multiply by 10000 to remove the decimal point.


这篇关于如何从double值中删除小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆