我有一個Excel工作表,其中我有幾列和一列是Amount
我必須驗證每個單元格並檢查它的長度在小數點後是否大於2,如果是,則拋出錯誤。獲取小數位數的長度
Public Function CheckLength(value As String) As Integer
Dim n As Double
Dim itg As Integer
Dim dcm As Double
n = value 'Say Value is 50.01 here
itg = Int(n) 'Will be 50
dcm = Split(n - itg, ".")(1) 'But n-itg will yield something and dcm`s value will be
'1000001 some strange value where as it has to be `01` or say whatever comes after decimal part
CheckLength = Len(dcm)
End Function
'num'?我希望它應該是'n'? –
沒有問題的朋友!讓我試試看!然後我認爲我不需要'itg'在這裏吧? –
美!完善!!接下來的4分鐘!用這個把我的頭一整天砸了.. :)這種方法有沒有什麼缺點?我的意思是它會忽略任何類型的價值,如你的知識! –