Function Math Arithmetic Class

FloatToFraction

Convert a floating point number into a fractional number represented by a string.

Signature (Visual Basic / VBA)

Public Function FloatToFraction( _
      ByVal vX As Variant _
    , ByVal vPrecision As Variant _
    ) As Variant

Code Example

    FloatToFraction(23.45678, 64) = "23 29/64"
    FloatToFraction(23.45678, 10) = "23 1/2"
    FloatToFraction(23.45678, 1E10) = "23 22839/50000"
    FloatToFraction(23.45678, 1) = "23" ' #4

Parameters

Parameter Description
vX The floating-point number that is to be converted to a fractional number and returned in string form. Function returns Null if vX is Null or cannot be fixed up to a number.
vPrecision The precision used when rounding vX. Function returns Null if vPrecision is Null or cannot be fixed up to a number. With a precision of 1 (one), function rounds all numbers to integers and returns them as strings as in example #4.