像抄表一样计算两个数字

时间:2013-01-07 21:22:52

标签: php

需要帮助。我正在制作电子计费系统,我遇到了解决2个号码最多99999的问题,之后它将回到00000.我将举例:

1st  reading ==== 00050
2nd  reading ==== 00100
3rd  reading ==== 01000
4th  reading ==== 10000
nth  reading ==== 99950
last reading ==== 00050

如何解决第n次和最后一次阅读?答案必须是100 ...我正在使用php代码

1 个答案:

答案 0 :(得分:2)

如果没有看到您的代码,很难确切知道您需要什么,但这样的事情将是一般方法:

// Assume you have $previous and $current
$difference = $current - $previous;
if ($difference < 0) {
    $difference = $current + (99999 - $previous);
}
相关问题