恐慌!需要将十进制转换为整数 [英] Panic! need to convert decimal to integer

查看:73
本文介绍了恐慌!需要将十进制转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我遇到的问题是我需要将小数转换为整数,如果我从0.000038mA的仪器读取天才谁写了这个烂摊子把它比作从ini文件19&读取的两个值。 50,19& 50毫安我认为,它总是失败,所以我需要一种方法将0.000038mA转换为38,(我已经尝试在ini文件中粘贴0.000019,但这不起作用)Convert.To没有帮助!!帮助Gimme Codez !!!!我正在通过转换为字符串和子串输出值来做,但是我无法确定小数位数....

格伦(嗯再次查看他的代码!)



BoardCurrentMeasuredString2 = BoardCurrentMeasuredString.Substring(BoardCurrentMeasuredString.Length - 2,BoardCurrentMeasuredString.Length)这不起作用!尝试下一个想法....

这里它落地

Hi All,

The problem I have is I need to convert a decimal to an integer, if I have the reading from an instrument of 0.000038mA the genius who wrote this mess compare it to two values read from ini file 19 & 50, 19 & 50 mA I assume, it always fails so I need a way of converting 0.000038mA to 38, (I have tried sticking 0.000019 in the ini file and that does not work) Convert.To doesn't help!! Help Gimme Codez !!!! I was looking at doing by converting to a string and substring out the values, however I can't be sure of the number of decimals....
Glenn (Hmm looking at his code again!)

BoardCurrentMeasuredString2 = BoardCurrentMeasuredString.Substring(BoardCurrentMeasuredString.Length - 2, BoardCurrentMeasuredString.Length) well that doesn't work! try the next idea....
here it lands

' MsgBox(Convert.ToString(BoardCurrentMeasured))
BoardCurrentMeasuredString = BoardCurrentMeasured.ToString()
MsgBox(BoardCurrentMeasuredString)
BoardCurrentMeasuredString.Trim()

StartPointString = (Val(BoardCurrentMeasuredString.Length - 2))
MsgBox(BoardCurrentMeasuredString.Length)
StopPointString = (Val(BoardCurrentMeasuredString.Length))
MsgBox(BoardCurrentMeasuredString.Length)

BoardCurrentMeasuredString2 = BoardCurrentMeasuredString.Substring(Convert.ToInt16(BoardCurrentMeasuredString.Length - 2), Convert.ToInt16(BoardCurrentMeasuredString.Length))
MsgBox(BoardCurrentMeasuredString2)


MsgBox(BoardCurrentHighVal)
MsgBox(BoardCurrentLowVal)
'BoardCurrentRead()



圣诞节午餐的坏词时间!!!

见Ya


Bad Words time for Christmas Lunch!!!
See Ya

推荐答案

假设你的字符串最后总是为mA,首先要做的就是摆脱它。有一些不同的方式,一个正则表达式可能是最灵活的,但...如果字符串总是以mA结束然后你可以作弊。

Assuming your string always as mA at the end, the first thing to do is get rid of it. There are a load of different ways, and a Regex is probably the most flexible, but...if the string always does end "mA" then you can cheat.
string input = "0.000038mA";
double d = Convert.ToDouble(input.Substring(0, input.Length - 2));
int value = (int)(d * 1000000);



您可以跳过双重转换:


You could skip the double conversion:

string input = "0.000038mA";
int value = Convert.ToInt32(input.Substring(2, input.Length - 4));

但是......







对不起,我忘了你爱VB这么多......

But...


[edit]
Sorry, I forgot you love VB so much...

Dim input As String = "0.000038mA"
Dim d As Double = Convert.ToDouble(input.Substring(0, input.Length - 2))
Dim value As Integer = CInt(Math.Truncate(d * 1000000))






And

Dim input As String = "0.000038mA"
Dim value As Integer = Convert.ToInt32(input.Substring(2, input.Length - 4))



[/ edit]


[/edit]


这篇关于恐慌!需要将十进制转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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