我有一列数字,我需要保留为数字,但将长度限制为20个字符。
Sub casecheck()
Dim myString As String
Dim newString As String
Dim char As Variant
'replace all special characters with nothing
Const SpecialCharacters As String = "!,.,#,$,%,^,&,-,(,),{,[,],},/,\, "
For i = 2 To trans
myString = Worksheets("Data Input").Cells(i, 10).Value
newString = myString
For Each char In Split(SpecialCharacters, ",")
newString = Replace(newString, char, "")
Worksheets("ExpertPay Feed").Cells(i, 3).Value = newString
Worksheets("ExpertPay Feed").Cells(i, 3).NumberFormat = "0"
Next
Next i
'trim length down to 20 characters
For i = 2 To trans
Worksheets("ExpertPay Feed").Cells(i, 3).Value = Left(Worksheets("ExpertPay Feed").Cells(i, 3).Value, 20)
Next i
End Sub
我的代码工作得非常好,除非我的数字非常长。例如:
此原始号码:1.31137E + 17变成13113690920150400000000000000000 而我似乎无法削减所有额外的零!
答案 0 :(得分:0)
尝试此功能:
public int get_life_total(){
return life + endurance;
}
有时可以很容易地将数字视为文本。