Link to home
Start Free TrialLog in
Avatar of wzm
wzm

asked on

VB6

Hi,
  How to use format to chop off the long trail decimal without rounding (up and down ) it and up to 2 decimals only?

 e.g -  343.236788976
 to be  343.23 NOT 343.24


TQ!.
Avatar of omegaomega
omegaomega
Flag of Canada image

Hello, w2m,

I would use:

    Dim strResult As String
    strResult = Format(dblValue, "#0.000")
    strResult = Left(strResult, Len(strResult) - 1)

Another possibility would be:

    Format(Fix(100 * Value) / 100, "#0.00")

"Fix" returns the integer equal to or closer to zero than the argument.  Depending on how you want to deal with negative numbers you might want to use "Int" instead of "Fix".  "Int" returns the integer less than or equal to the argument.  (The above will "truncate" -123.456 to -123.45 whereas if "Int" is used it will return -123.46.)  

Cheers,
Randy
ASKER CERTIFIED SOLUTION
Avatar of ronklein
ronklein

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial