11 $format = self::stripQuotes($format);
13 $sign = ($value < 0.0) ?
'-' :
'';
15 $integerPart = floor(abs($value));
16 $decimalPart = trim(fmod(abs($value), 1),
'0.');
17 $decimalLength = strlen($decimalPart);
18 $decimalDivisor = 10 ** $decimalLength;
20 $GCD = MathTrig\Gcd::evaluate($decimalPart, $decimalDivisor);
22 $adjustedDecimalPart = $decimalPart / $GCD;
23 $adjustedDecimalDivisor = $decimalDivisor / $GCD;
25 if ((strpos($format,
'0') !==
false)) {
26 return "{$sign}{$integerPart} {$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
27 } elseif ((strpos($format,
'#') !==
false)) {
28 if ($integerPart == 0) {
29 return "{$sign}{$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
32 return "{$sign}{$integerPart} {$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
33 } elseif ((substr($format, 0, 3) ==
'? ?')) {
34 if ($integerPart == 0) {
38 return "{$sign}{$integerPart} {$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
41 $adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
43 return "{$sign}{$adjustedDecimalPart}/{$adjustedDecimalDivisor}";