在递增的数字中找到第一个 1/2,然后找到第一个整数

发布于 2024-11-03 01:21:16 字数 2425 浏览 8 评论 0原文

我正在使用 php 来运行日期列表。每个工作日日期都被分配一个百分比 1,然后按该百分比递增。

我需要能够标记第一个增量等于或大于 0.5,然后第一个增量等于或大于 1,然后随后等于或大于 0.5,然后每个整数都相同。

我遇到的问题并不是真正找到要标记的数字,而是忽略结果直到它再次出现。

我不能舍入比我所拥有的更多的舍入,因为从长远来看,舍入超过的舍入会以不同的方式伤害任何一方。

这是我所拥有的一小部分的输出,希望它更有意义。

2011-03-06 Weekend 
2011-03-07 Earned: 0.096154 Accrued: 0.096154
2011-03-08 Earned: 0.096154 Accrued: 0.192308
2011-03-09 Earned: 0.096154 Accrued: 0.288462
2011-03-10 Earned: 0.096154 Accrued: 0.384615
2011-03-11 Earned: 0.096154 Accrued: 0.480769
2011-03-12 Weekend 
2011-03-13 Weekend 
2011-03-14 Earned: 0.096154 Accrued: 0.576923 <- should be marked
2011-03-15 Earned: 0.096154 Accrued: 0.673077
2011-03-16 Earned: 0.096154 Accrued: 0.769231
2011-03-17 Earned: 0.096154 Accrued: 0.865385
2011-03-18 Earned: 0.096154 Accrued: 0.961538
2011-03-19 Weekend 
2011-03-20 Weekend 
2011-03-21 Earned: 0.096154 Accrued: 1.057692 <- should be marked
2011-03-22 Earned: 0.096154 Accrued: 1.153846
2011-03-23 Earned: 0.096154 Accrued: 1.25
2011-03-24 Earned: 0.096154 Accrued: 1.346154
2011-03-25 Earned: 0.096154 Accrued: 1.442308
2011-03-26 Weekend 
2011-03-27 Weekend 
2011-03-28 Earned: 0.096154 Accrued: 1.538462 <- should be marked 
2011-03-29 Earned: 0.096154 Accrued: 1.634615
2011-03-30 Earned: 0.096154 Accrued: 1.730769
2011-03-31 Earned: 0.096154 Accrued: 1.826923
2011-04-01 Earned: 0.096154 Accrued: 1.923077
2011-04-02 Weekend 
2011-04-03 Weekend 
2011-04-04 Earned: 0.096154 Accrued: 2.019231 <- should be marked
2011-04-05 Earned: 0.096154 Accrued: 2.115385
2011-04-06 Earned: 0.096154 Accrued: 2.211538
2011-04-07 Earned: 0.096154 Accrued: 2.307692
2011-04-08 Earned: 0.096154 Accrued: 2.403846
2011-04-09 Weekend 
2011-04-10 Weekend 
2011-04-11 Earned: 0.096154 Accrued: 2.5  <- should be marked
2011-04-12 Earned: 0.096154 Accrued: 2.596154
2011-04-13 Earned: 0.096154 Accrued: 2.69230

添加请求的代码。这里有很多输出,所以我可以看到它在做什么。一旦我知道它正在做我需要它做的事情,它将被删除。

注意 $x 这里是静态的,但会是动态的,所以我必须担心第一个小数点可能并不总是有 5 来告诉我它大约是 1/2

$startDate = '2011-01-01';
$x= 25/260; 
$y = 0;

while (strtotime($startDate) <= strtotime($today)) {

echo $startDate;
    if(is_weekday($startDate)) {
    $y = $x+$y;
    print ' Earned: '.round($x,6).' Accrued: '.round($y,6).'<br />';
    } else {
    print ' Weekend <br />';
    } 
$startDate = date ('Y-m-d', strtotime('+ 1 day', strtotime($startDate)));
}

I'm using php to run through a list of dates. Each date that is a weekday is being assigned a percentage of 1 then incremented by the percentage.

I need to be able to flag the first increment equal to or above .5 then the first increment equal to or above 1, then subsequently equal to or above .5 then the same for each whole number.

The problem I am having trouble with is not really finding the number to mark, but to ignore the result until it comes up again.

I can not round more than I have as rounding past that in the long run will hurt either party in a different way.

Here is the output of a small part of what I have in hopes that it makes more sense.

2011-03-06 Weekend 
2011-03-07 Earned: 0.096154 Accrued: 0.096154
2011-03-08 Earned: 0.096154 Accrued: 0.192308
2011-03-09 Earned: 0.096154 Accrued: 0.288462
2011-03-10 Earned: 0.096154 Accrued: 0.384615
2011-03-11 Earned: 0.096154 Accrued: 0.480769
2011-03-12 Weekend 
2011-03-13 Weekend 
2011-03-14 Earned: 0.096154 Accrued: 0.576923 <- should be marked
2011-03-15 Earned: 0.096154 Accrued: 0.673077
2011-03-16 Earned: 0.096154 Accrued: 0.769231
2011-03-17 Earned: 0.096154 Accrued: 0.865385
2011-03-18 Earned: 0.096154 Accrued: 0.961538
2011-03-19 Weekend 
2011-03-20 Weekend 
2011-03-21 Earned: 0.096154 Accrued: 1.057692 <- should be marked
2011-03-22 Earned: 0.096154 Accrued: 1.153846
2011-03-23 Earned: 0.096154 Accrued: 1.25
2011-03-24 Earned: 0.096154 Accrued: 1.346154
2011-03-25 Earned: 0.096154 Accrued: 1.442308
2011-03-26 Weekend 
2011-03-27 Weekend 
2011-03-28 Earned: 0.096154 Accrued: 1.538462 <- should be marked 
2011-03-29 Earned: 0.096154 Accrued: 1.634615
2011-03-30 Earned: 0.096154 Accrued: 1.730769
2011-03-31 Earned: 0.096154 Accrued: 1.826923
2011-04-01 Earned: 0.096154 Accrued: 1.923077
2011-04-02 Weekend 
2011-04-03 Weekend 
2011-04-04 Earned: 0.096154 Accrued: 2.019231 <- should be marked
2011-04-05 Earned: 0.096154 Accrued: 2.115385
2011-04-06 Earned: 0.096154 Accrued: 2.211538
2011-04-07 Earned: 0.096154 Accrued: 2.307692
2011-04-08 Earned: 0.096154 Accrued: 2.403846
2011-04-09 Weekend 
2011-04-10 Weekend 
2011-04-11 Earned: 0.096154 Accrued: 2.5  <- should be marked
2011-04-12 Earned: 0.096154 Accrued: 2.596154
2011-04-13 Earned: 0.096154 Accrued: 2.69230

Adding the requested code. There is a lot of output here, so I can see what it's doing. that will be removed once I know that it's doing what I need it to do.

Note on $x It's static here, but will be dynamic, so I have to be concerned that the first decimal point may not always have a 5 in it to tell me it's about 1/2

$startDate = '2011-01-01';
$x= 25/260; 
$y = 0;

while (strtotime($startDate) <= strtotime($today)) {

echo $startDate;
    if(is_weekday($startDate)) {
    $y = $x+$y;
    print ' Earned: '.round($x,6).' Accrued: '.round($y,6).'<br />';
    } else {
    print ' Weekend <br />';
    } 
$startDate = date ('Y-m-d', strtotime('+ 1 day', strtotime($startDate)));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-11-10 01:21:16

counter 设置为 1。继续,直到找到大于或等于 counter * 0.5 的值。标记它,将计数器增加1并重复。

Set a counter to 1. Proceed until you find a value greater than or equal to counter * 0.5. Mark it, increment the counter by 1 and repeat.

早茶月光 2024-11-10 01:21:16
$count = 1;
while(your loop for displaying said content, foreach() maybe)
{

   echo "{$timestamp} Earned: {$earned} Accrued: {$accrued}";
   if($accrued > ($count * 0.5)) { echo "<- should be marked"; $count++;}
   echo "<br/>";

}
$count = 1;
while(your loop for displaying said content, foreach() maybe)
{

   echo "{$timestamp} Earned: {$earned} Accrued: {$accrued}";
   if($accrued > ($count * 0.5)) { echo "<- should be marked"; $count++;}
   echo "<br/>";

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文