Home > Backend Development > PHP Tutorial > 数字进位的问题

数字进位的问题

WBOY
Release: 2016-06-06 20:47:15
Original
1306 people have browsed it

三个标准:金银铜

希望数字足够100的就向上进一位。

比如数字100211 = 10金2银11铜

用php写的话,怎么做效率最高?

回复内容:

三个标准:金银铜

希望数字足够100的就向上进一位。

比如数字100211 = 10金2银11铜

用php写的话,怎么做效率最高?

<code>function grade($point) {
    $copper = fmod($point, 100);
    $silver = (fmod($point, 10000) - $copper) / 100;
    $gold = floor($point/10000);
    return [$gold, $silver, $copper];
}
</code>
Copy after login

如果是存数字的话这样应该可以,当然如果说最效率的应该还是各个得分都存储了。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template