研究了一天,我这个代码小白总算搞出自己想要的效果啦,不发出来太浪费了
参考
使用效果
计算实际使用日期
.action{$deadline := index . "弃用" } .action{if empty $deadline} .action{$today:= (div (now.Sub .购入).Hours 24)} .action{$today} .action{else} .action{$today:= (div (.弃用.Sub .购入).Hours 24)} .action{$today} .action{end}
日均价格
保留 2 位小数点
.action{$deadline := index . "弃用" } .action{if empty $deadline} .action{$today:= (divf (now.Sub .购入).Hours 24)} .action{$money:= (divf .花费 $today)} .action{$money:= round $money 2} .action{$money} .action{else} .action{$a:= index . "花费" } .action{$b:= index . "回血" } .action{$result:= sub $a $b} .action{$today:= (divf (.弃用.Sub .购入).Hours 24)} .action{$money:= (divf $result $today)} .action{$money:= round $money 2} .action{$money} .action{end}
提前预知到了弃用后没写回血的情况并修复了 bug
.action{$deadline := index . "弃用" } .action{$a:= index . "花费" } .action{$b:= index . "回血" } .action{if empty $deadline} .action{$today:= (divf (now.Sub .购入).Hours 24)} .action{$money:= (divf .花费 $today)} .action{$money:= round $money 2} .action{$money} .action{else} .action{if empty $b} .action{$today:= (divf (.弃用.Sub .购入).Hours 24)} .action{$money:= (divf .花费 $today)} .action{$money:= round $money 2} .action{$money} .action{else} .action{$result:= sub $a $b} .action{$today:= (divf (.弃用.Sub .购入).Hours 24)} .action{$money:= (divf $result $today)} .action{$money:= round $money 2} .action{$money} .action{end} .action{end}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于