tags:

views:

750

answers:

3

I need to display 45.556 as 45.55 what is the format i need to use in true dbgrid pro 7.0.

+2  A: 

Sorry not familiar with dbgird pro 7.0. If you are looking not looking to trucate the 6 as you showed in your example (rounded 45.556 is 45.56) you can use the format command, which will format your number to two decimal places, rounding accordingly.

format(*value*, "0.00")

Using "0.00" formats the number to default to zero in the position the zero is in.
Using "#.##" formats the number to default to space (nothing)

If you don't want to round the number and are only looking to get the number plus the right two decimal places.

Left(cStr(value), instr(cStr(value), ".") + 2))

Retrieves from the left your number plus 2 past the decimal, truncating the rest. You may not need to cStr(), as VB may explicitly convert it first.
using cStr() may create a space before the number which is from a minus sign would go, format() doesn't do this, if you see this issue in your grid.

Brettski
A: 

To handle this through the grids properties, set the column's NumberFormat = Fixed, unless it is a currency value, then you should use Currency.

cmsjr
A: 

Optionally without resulting to string manipulation that will blow up in European countries (which use a , instead of a . for the decimal place)... However, if any combination of floatval and decimalPlaces > 9 you are going to have overflow issues...

Public Function Floor(ByVal floatval As Double, optional decimalPlaces as Long = 0) As Long
    Dim intval As Long
    intval = Round(floatval)
    If intval > floatval Then 
         intval = intval - 1
    End If

    if decimalPlaces > 0 then
        floatval = float / (10 ^ decimalPlaces)
    end if

    Floor = intval
End Function
Kris Erickson