How to round to nearest Thousand?

前端 未结 8 661
独厮守ぢ
独厮守ぢ 2020-12-06 03:59

How Do I round a number to its nearest thousand?

function round($var) {
    // Round it
}
8条回答
  •  旧时难觅i
    2020-12-06 04:41

    Use the round function as mentioned by other posters round($number, -3).

    You can also, divide your number by 1,000, round to nearest whole number then multiply by 1,000.

    Also, if you want to round up, you can divide by 1,000, negate the quotient, coerce it to an integer, negate it again and then multiply it by 1,000.

提交回复
热议问题