ข้ามไปที่เนื้อหาหลัก

บทความ

กำลังแสดงโพสต์จาก กันยายน, 2011

สร้าง function floor()จำเป็น ใช้เอง

จะเขียนโปรแกรมปัดเศษทศนิยมทิ้ง เห็นใน Visual Studio 2008 มี DataColumns.Expression ให้ใช้ ง๊ายยย........ง่าย... ไม่ต้องเปลืองแรงคำนวณเอง แต่.... แม่เจ้า ไม่มีฟังก์ชัน floor ให้ใช้ ด้วยความขี้เกียจรื้อโค้ด (ถ้ารื้อแล้วใช้ LINQ จะเสียเวลาน้อยกว่านี้) เลยพยายามใช้เครื่องมือของ Expression เท่าที่มี หน้าตาสูตร Expression ที่ให้ผลลัพธ์เป็น floor จึงออกมาประมาณนี้  Using datacolumn As New DataColumn() With {.DataType = GetType(Integer), .ColumnName = "SPToInt", .Caption = "แต้ม", .Expression = "SumPrice*100", .AllowDBNull = True}                 Datatable.Columns.Add(datacolumn)             End Using Using datacolumn As New DataColumn() With {.DataType = GetType(Integer), .ColumnName = "SPMod100", .Caption = "แต้ม", .Expression = "SPToInt%100", .AllowDBNull = True}                 Datatable.Columns.Add(datacolumn)             End Using  Using datacolumn As New DataColumn() With {.DataType = GetType(Integer), .ColumnName = "Tru