从双获得的小数部分 [英] Get the decimal part from a double

查看:113
本文介绍了从双获得的小数部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个整数形式的小数点后收到的号码。例如,只有05从1.05或2.50只50的不可以 0.50

I want to receive the number after the decimal dot in the form of an integer. For example, only 05 from 1.05 or from 2.50 only 50 not 0.50

推荐答案

- 更新 -

-- UPDATED --

- 输入samples--
双myvalue的= 46.0
双myvalue的= 46.01
双myvalue的= 46.000001
双myvalue的= 46.1
双myvalue的= 46.12
双myvalue的= 46.123
双myvalue的= 46.1234

--input samples--
double MyValue = 46.0
double MyValue = 46.01
double MyValue = 46.000001
double MyValue = 46.1
double MyValue = 46.12
double MyValue = 46.123
double MyValue = 46.1234

- method--

--method--

 string outPut = "0";
 if (MyValue.ToString().Split('.').Length == 2)
 {
 outPut = MyValue.ToString().Split('.')[1].Substring(0, MyValue.ToString().Split('.')[1].Length);
 }
 Console.WriteLine(outPut);

- outputs--
1)0
2)01
3)000001
4)1
5)12
6)123
7)1234

--outputs--
1) 0
2) 01
3) 000001
4) 1
5) 12
6) 123
7) 1234

这篇关于从双获得的小数部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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