We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51020
    • 670 Posts
    Wow - thank you so much for your time and effort. I love this community!!
    I will implement this and see his it works - but it looks perfect.

    Thanks again. I'll report back once I've tested it.

    You're a legend.
    Andy
      • 51020
      • 670 Posts
      Wow thank you - I'll have a go with this too.
        • 51020
        • 670 Posts
        Is there any way this can round DOWN instead of round up though?
          • 42562
          • 1,145 Posts
          Are you only interested in Million and Thousands ?
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 3749
            • 24,544 Posts
            How about something like this:

            $input = str_replace(',','', $input);
            return floor($input / 100000) / 10;
            


              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 51020
              • 670 Posts
              Quote from: donshakespeare at May 12, 2017, 05:24 PM
              Are you only interested in Million and Thousands ?

              Millions, thousands, tens of thousand, hundreds of thousands.
                • 51020
                • 670 Posts
                Quote from: BobRay at May 13, 2017, 12:50 AM
                How about something like this:

                $input = str_replace(',','', $input);
                return floor($input / 100000) / 10;
                



                Thanks. I tried something similar but I will give this a go tonight. Thanks.
                  • 3749
                  • 24,544 Posts
                  It produces 1.2 from your input number for me, but I think it may produce 1.0 instead of 1 for numbers under 1.1 million. I think this would fix that:

                  $input = str_replace(',','', $input);
                  $output = floor($input / 100000) / 10;
                  return $output < 1.1? 1 : $output;
                  
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 51020
                    • 670 Posts
                    Quote from: tm2000 at May 13, 2017, 01:20 AM
                    Quote from: BobRay at May 13, 2017, 12:50 AM
                    How about something like this:

                    $input = str_replace(',','', $input);
                    return floor($input / 100000) / 10;
                    



                    Thanks. I tried something similar but I will give this a go tonight. Thanks.

                    Quote from: BobRay at May 13, 2017, 10:06 AM
                    It produces 1.2 from your input number for me, but I think it may produce 1.0 instead of 1 for numbers under 1.1 million. I think this would fix that:

                    $input = str_replace(',','', $input);
                    $output = floor($input / 100000) / 10;
                    return $output < 1.1? 1 : $output;
                    

                    Thanks Bob - I'm not sure how to use this - would it be an output filter? I can't get it to work - so I'm obviously using it wrong. I assumed it would be:

                    [[$myBigNunber:yourSnippet]]
                      • 51020
                      • 670 Posts
                      Quote from: clareoconsulting at May 12, 2017, 02:02 PM
                      Created a quick hack that matches your use case as I see it, but gives you a bit of flexibility for how to output numbers with different numbers of digits. It's a bit inelegant and procedural, but appears to give what you're looking for.

                      Tinker with the 5 arrays at the top to adjust the display to different input lengths. NOTE: Only good as-is for up to 999,999,999, but you could add more array entries if you want to go higher. See sample outputs below code.
                      <!--?php
                          // Configure the following 5 arrays to control output based on
                          // the number of digits in the input number
                      
                          // Cases where output will be displayed in multiples, i.e. "5 million"
                          // instead of "5,000,000". Enter the number to divide by (eg. 1000000 for a million,
                          // 1000 for a thousand, 1 for no division)
                          $displayDivisor = array(
                              1 =--> 1,
                              2 => 1,
                              3 => 1,
                              4 => 1,
                              5 => 1,
                              6 => 1,
                              7 => 1000000,
                              8 => 1000000,
                              9 => 1000000
                          );
                          
                          // Precision of rounding of input. Eg. 3 rounds at thousands
                          // 6 rounds at millions, 5 rounds to tenth of million, etc.
                          $roundingDigits = array(
                              1 => 0,
                              2 => 0,
                              3 => 0,
                              4 => 2,
                              5 => 3,
                              6 => 3,
                              7 => 5,
                              8 => 6,
                              9 => 6
                          );
                          
                          // How many decimal places to display in the output
                          $displayDecimals = array(
                              1 => 0,
                              2 => 0,
                              3 => 0,
                              4 => 0,
                              5 => 0,
                              6 => 0,
                              7 => 1,
                              8 => 0,
                              9 => 0
                          );
                      
                          // Text prefix for output
                          $displayPrefix = array(
                              1 => '',
                              2 => '',
                              3 => '',
                              4 => 'more than ',
                              5 => 'more than ',
                              6 => 'more than ',
                              7 => 'more than ',
                              8 => 'more than ',
                              9 => 'more than '
                          );
                          
                          // Text suffix for output
                          $displaySuffix = array(
                              1 => '',
                              2 => '',
                              3 => '',
                              4 => '',
                              5 => '',
                              6 => '',
                              7 => ' million',
                              8 => ' million',
                              9 => ' million'
                          );
                      
                      
                          // CHANGE NOTHING AFTER THIS POINT
                          $value              = floatval($input);
                          $digitCount         = intval(log10($value)) + 1;
                          
                          if (! isset($displayDivisor[$digitCount]) || 
                              ! isset($roundingDigits[$digitCount]) || 
                              ! isset($displayDecimals[$digitCount]) || 
                              ! isset($displayPrefix[$digitCount]) || 
                              ! isset($displaySuffix[$digitCount])
                              ) { return ''; }
                          
                          $roundingPrecision  = pow(10, $roundingDigits[$digitCount]);
                          $floorValue         = floor($value / $roundingPrecision) * $roundingPrecision / $displayDivisor[$digitCount];
                          $outputValue        = number_format($floorValue, $displayDecimals[$digitCount]);
                          
                          $output = $displayPrefix[$digitCount] .  
                                    $outputValue .
                                    $displaySuffix[$digitCount];
                      
                          $return $output;
                      


                      Sample (Input | Output)

                      • 1 | 1
                      • 12 | 12
                      • 123 | 123
                      • 1234 | more than 1,200
                      • 12345 | more than 12,000
                      • 123456 | more than 123,000
                      • 1234567 | more than 1.2 million
                      • 12345678 | more than 12 million
                      • 123456789 | more than 123 million

                      Hi there - trying to use this now - but not sure what I need to activate this snippet?
                      Is it to be used as an output filter somehow?