Link to home
Start Free TrialLog in
Avatar of kar8942
kar8942

asked on

VB Significant Digits function

Does anyone have a visual basic function that will return a passed number with a requested number of significant digits?
For example:
X = 1.233412
Y = FixSigFigs(X,3) 'I want Y to have 3 significant digits.

Function FixSigFigs( NumberToFix as double, SigFigs as Integer)

SOLUTION
Avatar of AlexFM
AlexFM

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
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

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
You didn't specify as to whether you wanted rounding or not.  Use the Round() function, as AlexFM suggested, if you need rounding to occur.  Otherwise, use my function if you simply want to truncate the number to the requested number of digits.
ASKER CERTIFIED SOLUTION
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
What did you decide to use?
Avatar of AlexFM
AlexFM

kar8942 got two ways: rounding and truncating. He should decide what he need. Without his response I think points should be splitted.
Avatar of kar8942

ASKER

Neither answer actually worked, but I will split the points anyway. Thanks.