十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
DataGridViewCellStyle方法不通用,區(qū)域性設(shè)置太麻煩了。
成都創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作與策劃設(shè)計(jì),偃師網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:偃師等地區(qū)。偃師做網(wǎng)站價(jià)格咨詢:13518219792
以下是程序方法:
可以先將數(shù)據(jù)源放入一張表中,不要直接綁定。新表是可以改string的。
那個列必須是string,不能是single
代碼寫在cellendedit的過程中,每次用戶退出單元格編輯后引發(fā)
dim a1 as single
dim a2 as string
Try
a1=csng(當(dāng)前單元格值)
Catch ex As Exception
MessageBox.Show("輸入條件不符合要求!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
if a11 then
a2=formate(a1,"0.0000")
else
....
endif
完事后a2賦值給當(dāng)前單元格即可。
用這個函數(shù)把
Math.Round 方法 (Decimal, Int32)
將小數(shù)值舍入到指定精度。
命名空間: System
程序集: mscorlib(在 mscorlib.dll 中)
語法
Visual Basic(用法)
Dim d As Decimal
Dim decimals As Integer
Dim returnValue As Decimal
returnValue = Math.Round(d, decimals)
參數(shù)
d
類型:System.Decimal
要舍入的小數(shù)。
decimals
類型:System.Int32
返回值中的小數(shù)位數(shù)(精度)。
返回值
類型:System.Decimal
精度等于 decimals,最接近 d 的數(shù)字。
Math.Round(3.4666666, 4) 結(jié)果是 3.4667.
保留兩位小數(shù)的一般方法是四舍五入法。
保留兩位小數(shù),看千分位。是4或比4小舍去;是5或比5大舍去以后向前一位進(jìn)1。
如:3.425保留兩位小數(shù)就是3.43
3.421保留兩位小數(shù)就是3.42
又如: 3.4263保留兩位小數(shù)就是3.43
3.4233保留兩位小數(shù)就是3.42
再如:3.4保留兩位小數(shù)就是3.40
舉個例子
Dim a As Decimal = 1.999
Dim b As Decimal = Math.Round(a, 2)
結(jié)果為b = 2.00
四舍五入保留兩位