159 posts
    Has sold $100+ on Envato Market Has been a beta tester for an Envato feature Has collected 10+ items on Envato Market Has been part of the Envato Community for over 2 years
+1 more
s4nji says


Here, I made one with preg_match_all, pretty much worked :)
Sanji thats pretty awesome work, may i use your code too. thankyou :)
Yes, you may use it, you’re welcome :D
5461 posts
    Has been part of the Envato Community for over 4 years Has referred 1+ members Located in Australia Has sold $1,000+ on Envato Market
+4 more
Australia says

What is code, for adding a var and echoing it out using the code you made please, just as a sample.

159 posts
    Has sold $100+ on Envato Market Has been a beta tester for an Envato feature Has collected 10+ items on Envato Market Has been part of the Envato Community for over 2 years
+1 more
s4nji says

What is code, for adding a var and echoing it out using the code you made please, just as a sample.
echo denominate($_GET['n']);
Why do you ask?
5461 posts
    Has been part of the Envato Community for over 4 years Has referred 1+ members Located in Australia Has sold $1,000+ on Envato Market
+4 more
Australia says


What is code, for adding a var and echoing it out using the code you made please, just as a sample.
echo denominate($_GET['n']);
Why do you ask?

I must be having a brain fart ( its late and been a long day )

<?php
    $numb ='125678767';
    function denominate($number) {
    // Define the denominators
    $value = array( 'thousand','million','billion','trillion' );
    // Use preg_match_all to gather datas
    $pattern = '/(\d+),(.+)/';
    preg_match_all( $pattern, $number, $result );
    // Get the first block of numbers
    $main = $result[1][0];
    // Get and specify the text for the value denominator
    $sub = substr_count( $result[2][0], ',' );
    $sub = $value[$sub];
    // Get the 'numbers behind the comma'
    $float = str_replace ( ',', '', $result[2][0] );
    $float = round( $float, 2 - strlen( $float ) );
    $float = substr( $float, 0, 2 );
    // Output
    return "$main,$float $sub";
}
?>
<?php echo denominate($_GET['numb']); ?>
159 posts
    Has sold $100+ on Envato Market Has been a beta tester for an Envato feature Has collected 10+ items on Envato Market Has been part of the Envato Community for over 2 years
+1 more
s4nji says
$number = '12,345,678,901';

function denominate($number) {
    // Define the denominators
    $value = array( 'thousand','million','billion','trillion' );
    // Use preg_match_all to gather datas
    $pattern = '/(\d+),(.+)/';
    preg_match_all( $pattern, $number, $result );
    // Get the first block of numbers
    $main = $result[1][0];
    // Get and specify the text for the value denominator
    $sub = substr_count( $result[2][0], ',' );
    $sub = $value[$sub];
    // Get the 'numbers behind the comma'
    $float = str_replace ( ',', '', $result[2][0] );
    $float = round( $float, 2 - strlen( $float ) );
    $float = substr( $float, 0, 2 );
    // Output
    return "$main,$float $sub";
}

echo denominate($number);

You don’t know how to use functions? You are having a brain fart, or… :grin:
By the way, the inputted numbers must be separated with comma manually, like the numbers you wrote at your first post.

5461 posts
    Has been part of the Envato Community for over 4 years Has referred 1+ members Located in Australia Has sold $1,000+ on Envato Market
+4 more
Australia says

Thanks, I never mentioned I knew what i was doing ! lol

639 posts
    Has sold $100+ on Envato Market Has collected 10+ items on Envato Market Sells items exclusively on Envato Market Has been part of the Envato Community for over 2 years
+1 more
Crakken says

Here, I made one with preg_match_all, pretty much worked :)

I’m not a big fan of preg_match but it works out really great. Good job. :)

by
by
by
by
by
by