Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Get thousand from number

Tags:

php

When the user enters a number from 1000 and above I want to be able to get the thousand for that number in an array.

For example…

Number entered by user: 165124

My array should return:

array('thousand_low' => 165000, 'thousand_high' = 165999)

Thanks!

like image 306
Per Sandström Avatar asked Jul 24 '26 17:07

Per Sandström


1 Answers

The complete array-returning function, using PHP's native floor and ceil functions:

function get_thousands($num) {
  return array(
    'thousand_low'=>floor($num/1000)*1000,
    'thousand_high'=>ceil($num/1000)*1000-1
  );
}
like image 192
Jens Roland Avatar answered Jul 26 '26 07:07

Jens Roland