SwatI18N/SwatI18NLocale.php
protected function formatIntegerGroupings(
        $value,
        SwatI18NNumberFormat $format
    ) {
        // group integer part with thousands separators
        $grouping_values = array();
        $groupings = $format->grouping;
        $grouping_total = intval(floor(abs($value)));
        if (
            count($groupings) === 0 ||
            $grouping_total === 0 ||
            $format->thousands_separator == ''
        ) {
            array_push($grouping_values, $grouping_total);
        } else {
            $grouping_previous = 0;
            while (count($groupings) > 1 && $grouping_total > 0) {
                $grouping = array_shift($groupings);

                if ($grouping === 0) {
                    // a grouping of 0 means use previous grouping
                    $grouping = $grouping_previous;
                } elseif ($grouping === CHAR_MAX) {
                    // a grouping of CHAR_MAX means no more grouping
                    array_push($grouping_values, $grouping_total);
                    break;
                } else {
                    $grouping_previous = $grouping;
                }

                $grouping_value = floor(
                    fmod($grouping_total, pow(10, $grouping))
                );

                $grouping_total = floor($grouping_total / pow(10, $grouping));
                if ($grouping_total > 0) {
                    $grouping_value = str_pad(
                        $grouping_value,
                        $grouping,
                        '0',
                        STR_PAD_LEFT
                    );
                }

                array_push($grouping_values, $grouping_value);
            }

            // last grouping repeats until integer part is finished
            $grouping = array_shift($groupings);

            // a grouping of CHAR_MAX means no more grouping
            if ($grouping === CHAR_MAX) {
                array_push($grouping_values, $grouping_total);
            } else {
                // a grouping of 0 means use previous grouping
                if ($grouping === 0) {
                    $grouping = $grouping_previous;
                }

                // a grouping of 0 as the last grouping means no more grouping
                if ($grouping === 0) {
                    array_push($grouping_values, $grouping_total);
                } else {
                    while ($grouping_total > 0) {
                        $grouping_value = floor(
                            fmod($grouping_total, pow(10, $grouping))
                        );

                        $grouping_total = floor(
                            $grouping_total / pow(10, $grouping)
                        );

                        if ($grouping_total > 0) {
                            $grouping_value = str_pad(
                                $grouping_value,
                                $grouping,
                                '0',
                                STR_PAD_LEFT
                            );
                        }

                        array_push($grouping_values, $grouping_value);
                    }
                }
            }
        }

        $grouping_values = array_reverse($grouping_values);

        // join groupings using thousands separator
        $formatted_value = implode(
            $format->thousands_separator,
            $grouping_values
        );

        return $formatted_value;
    }
protected function formatIntegerGroupings(
        $value,
        SwatI18NNumberFormat $format
    ) {
        // group integer part with thousands separators
        $grouping_values = array();
        $groupings = $format->grouping;
        $grouping_total = intval(floor(abs($value)));
        if (
            count($groupings) === 0 ||
            $grouping_total === 0 ||
            $format->thousands_separator == ''
        ) {
            array_push($grouping_values, $grouping_total);
        } else {
            $grouping_previous = 0;
            while (count($groupings) > 1 && $grouping_total > 0) {
                $grouping = array_shift($groupings);

                if ($grouping === 0) {
                    // a grouping of 0 means use previous grouping
                    $grouping = $grouping_previous;
                } elseif ($grouping === CHAR_MAX) {
                    // a grouping of CHAR_MAX means no more grouping
                    array_push($grouping_values, $grouping_total);
                    break;
                } else {
                    $grouping_previous = $grouping;
                }

                $grouping_value = floor(
                    fmod($grouping_total, pow(10, $grouping))
                );

                $grouping_total = floor($grouping_total / pow(10, $grouping));
                if ($grouping_total > 0) {
                    $grouping_value = str_pad(
                        $grouping_value,
                        $grouping,
                        '0',
                        STR_PAD_LEFT
                    );
                }

                array_push($grouping_values, $grouping_value);
            }

            // last grouping repeats until integer part is finished
            $grouping = array_shift($groupings);

            // a grouping of CHAR_MAX means no more grouping
            if ($grouping === CHAR_MAX) {
                array_push($grouping_values, $grouping_total);
            } else {
                // a grouping of 0 means use previous grouping
                if ($grouping === 0) {
                    $grouping = $grouping_previous;
                }

                // a grouping of 0 as the last grouping means no more grouping
                if ($grouping === 0) {
                    array_push($grouping_values, $grouping_total);
                } else {
                    while ($grouping_total > 0) {
                        $grouping_value = floor(
                            fmod($grouping_total, pow(10, $grouping))
                        );

                        $grouping_total = floor(
                            $grouping_total / pow(10, $grouping)
                        );

                        if ($grouping_total > 0) {
                            $grouping_value = str_pad(
                                $grouping_value,
                                $grouping,
                                '0',
                                STR_PAD_LEFT
                            );
                        }

                        array_push($grouping_values, $grouping_value);
                    }
                }
            }
        }

        $grouping_values = array_reverse($grouping_values);

        // join groupings using thousands separator
        $formatted_value = implode(
            $format->thousands_separator,
            $grouping_values
        );

        return $formatted_value;
    }
protected function formatIntegerGroupings ( $ value , SwatI18NNumberFormat $ format ) { // group integer part with thousands separators $ grouping_values = array ( ) ; $ groupings = $ format -> grouping ; $ grouping_total = intval ( floor ( abs ( $ value ) ) ) ; if ( count ( $ groupings ) === 0 || $ grouping_total === 0 || $ format -> thousands_separator == '' ) { array_push ( $ grouping_values , $ grouping_total ) ; } else { $ grouping_previous = 0 ; while ( count ( $ groupings ) > 1 && $ grouping_total > 0 ) { $ grouping = array_shift ( $ groupings ) ; if ( $ grouping === 0 ) { // a grouping of 0 means use previous grouping $ grouping = $ grouping_previous ; } elseif ( $ grouping === CHAR_MAX ) { // a grouping of CHAR_MAX means no more grouping array_push ( $ grouping_values , $ grouping_total ) ; break ; } else { $ grouping_previous = $ grouping ; } $ grouping_value = floor ( fmod ( $ grouping_total , pow ( 10 , $ grouping ) ) ) ; $ grouping_total = floor ( $ grouping_total / pow ( 10 , $ grouping ) ) ; if ( $ grouping_total > 0 ) { $ grouping_value = str_pad ( $ grouping_value , $ grouping , '0' , STR_PAD_LEFT ) ; } array_push ( $ grouping_values , $ grouping_value ) ; } // last grouping repeats until integer part is finished $ grouping = array_shift ( $ groupings ) ; // a grouping of CHAR_MAX means no more grouping if ( $ grouping === CHAR_MAX ) { array_push ( $ grouping_values , $ grouping_total ) ; } else { // a grouping of 0 means use previous grouping if ( $ grouping === 0 ) { $ grouping = $ grouping_previous ; } // a grouping of 0 as the last grouping means no more grouping if ( $ grouping === 0 ) { array_push ( $ grouping_values , $ grouping_total ) ; } else { while ( $ grouping_total > 0 ) { $ grouping_value = floor ( fmod ( $ grouping_total , pow ( 10 , $ grouping ) ) ) ; $ grouping_total = floor ( $ grouping_total / pow ( 10 , $ grouping ) ) ; if ( $ grouping_total > 0 ) { $ grouping_value = str_pad ( $ grouping_value , $ grouping , '0' , STR_PAD_LEFT ) ; } array_push ( $ grouping_values , $ grouping_value ) ; } } } } $ grouping_values = array_reverse ( $ grouping_values ) ; // join groupings using thousands separator $ formatted_value = implode ( $ format -> thousands_separator , $ grouping_values ) ; return $ formatted_value ; }
Formats the integer part of a value according to format-specific numeric
groupings

This is a number formatting helper method. It is responsible for
grouping integer-part digits. Grouped digits are separated using the
thousands separator character specified by the format object.

@param float $value the value to format.
@param SwatI18NNumberFormat the number format to use.

@return string the grouped integer part of the value.
Formats the integer part of a value according to format - specific numeric groupings