Created
December 5, 2013 22:50
-
-
Save craibuc/7815455 to your computer and use it in GitHub Desktop.
Converts a fractional value in the format of Numerator/Denominator or Whole + Numerator/Denominator to a decimal value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Assumes values in the following formats: | |
| //99 - integer value | |
| //99.9 - decimal value | |
| //N/D - numerator/denominator | |
| //M N/D - whole + numerator/denominator | |
| Function (Stringvar value) | |
| Local Numbervar whole := 0; | |
| Local Stringvar fraction; | |
| // | |
| value := trim(value); | |
| //integer or decimal format | |
| If IsNumeric(value) Then | |
| ToNumber(value) | |
| Else ( | |
| //whole + numerator/denominator | |
| If InStr(value, " ")>0 Then ( | |
| whole := ToNumber(Split(value, " ")[1]); | |
| fraction := Split(value, " ")[2]; | |
| ) | |
| //numerator/denominator | |
| Else ( | |
| fraction := value; | |
| ); | |
| Local Numbervar numerator := ToNumber(Split(fraction, "/")[1]); | |
| Local Numbervar denominator := ToNumber(Split(fraction, "/")[2]); | |
| whole + (numerator / denominator); | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment