我有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. T-SQL十進制分割精度
- 2. 十進制數字切割
- 3. 如何在bc中分割時得到十進制數?
- 4. 在VB.NET中將十六進制值存儲在一個變量中(Dim xx爲「十六進制」)
- 5. VB.NET - 分割成多個分割號碼
- 6. 在VB.NET中將十進制轉換爲二進制
- 7. VB.Net - 將多字節十六進制值轉換爲十進制
- 8. 轉換十進制值來獲得進展分割二元4GL
- 9. 將十六進制拆分爲2個十六進制值
- 10. 在vb.net中分割一個字符串(無分隔符)
- 11. 在二進制分隔符上分割一個二進制文件?
- 12. 在java中分割並回傳一個二進制文件
- 13. 在sql中拆分十進制
- 14. 選擇一個十六進制附近的十六進制數
- 15. 十六進制爲二進制和十進制在matlab中
- 16. vb.net - 十六進制,按位問題
- 17. VB.net MD5校驗,以十六進制
- 18. 使用java分割十進制值(如字符串)
- 19. 如何將圖像分割爲十六進制代碼像素?
- 20. 分割錯誤C++十六進制計算器
- 21. 使用移位運算符分割大數十進制數
- 22. 分割字符串在VB.net
- 23. 在python中分割十六進制的最佳方法是什麼?
- 24. 如何在Python中分割多語言行並獲取Unicode十六進制值?
- 25. VB.net:顯示十進制值的某些部分
- 26. 分割使用VB.net
- 27. 十進制分隔符oracle
- 28. java十進制分隔符
- 29. 在VB.NET中將字符串轉換爲十進制
- 30. 將十進制轉換爲十六進制和十六進制
請問我可以讓我知道關於如何做到這一點的整個代碼 – 2010-04-03 20:15:47
OP根據問題的標題使用了Decimal。 – Joey 2010-04-03 20:22:26
@JohannesRössel - 比我的眼睛更銳利......答案更正了 – Oded 2010-04-03 20:35:56