我有532.016,我只想在VB.NET中得到532部分。我怎樣才能做到這一點?在VB.NET中分割一個'十進制'
0
A
回答
9
Math.Truncate(myDecimal)
將剝去的小數部分,只留下一部分(而不是改變類型;即,這將返回該參數的類型,以及,是它Double
或Decimal
) 。
3
將其轉換爲整數。
Dim myDec As Decimal
myDecimal = 532.016
Dim i As Integer = Cint(myDecimal)
'i now contains 532
0
你可以使用System.Text.RegularExpressions:
Imports System.Text.RegularExpressions 'You need this for "Split"'
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim yourNumber As String = 532.016 'You could write your integer as a string or convert it to a string'
Dim whatYouWant() As String 'Notice the "(" and ")", these are like an array'
whatYouWant = Split(yourNumber, ".") 'Split by decimal'
MsgBox(whatYouWant(0)) 'The number you wanted is before the first decimal, so you want array "(0)", if wanted the number after the decimal the you would write "(1)"'
End Sub
End Class
0
Decimal.floor(532.016)
也將返回532
Decimal.Floor
回合下來到最接近的整數。
但它不適用於負數。 See this Stack Overflow question for a complete explanation
Decimal.Truncate
(或Math.Truncate
)真的是您的案例中的最佳選擇。
相關問題
- 1. VB.net十進制值
- 2. T-SQL十進制分割精度
- 3. 分割字符串(十六進制)分爲兩個字母塊
- 4. 十進制數字切割
- 5. 如何在bc中分割時得到十進制數?
- 6. 在VB.NET中將十六進制值存儲在一個變量中(Dim xx爲「十六進制」)
- 7. 拆分一個十六進制數
- 8. VB.NET - 分割成多個分割號碼
- 9. 在VB.NET中將十進制轉換爲二進制
- 10. VB.Net - 將多字節十六進制值轉換爲十進制
- 11. 轉換十進制值來獲得進展分割二元4GL
- 12. 將十六進制拆分爲2個十六進制值
- 13. 我想分割,而我正在寫Ints轉換十進制到二進制
- 14. 分割二進制
- 15. 在vb.net中分割一個字符串(無分隔符)
- 16. 字符被分配到一個特定的十六進制值/十進制值
- 17. 在二進制分隔符上分割一個二進制文件?
- 18. 在java中分割並回傳一個二進制文件
- 19. 在sql中拆分十進制
- 20. 將十進制數截斷爲一個十進制數
- 21. 選擇一個十六進制附近的十六進制數
- 22. 十六進制爲二進制和十進制在matlab中
- 23. vb.net大於十進制數據類型
- 24. AES加密輸出十六進制vb.net
- 25. vb.net - 十六進制,按位問題
- 26. VB.net MD5校驗,以十六進制
- 27. VB.Net反向字節十六進制值
- 28. 使用移位運算符分割大數十進制數
- 29. 分割字符串,然後解析爲十進制
- 30. 使用java分割十進制值(如字符串)
請問我可以讓我知道關於如何做到這一點的整個代碼 – 2010-04-03 20:15:47
OP根據問題的標題使用了Decimal。 – Joey 2010-04-03 20:22:26
@JohannesRössel - 比我的眼睛更銳利......答案更正了 – Oded 2010-04-03 20:35:56