Decimals in Visual Basic 6.0

vb6

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

Best Answer

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.

Related Topic