'Math.floor is counting var without decimals [closed]
I got this in one longer script:
var formatIn = function(momentInMinutes){
var message = '';
var days = 0;
var now = toMinutes(getCurrentHourFormatted());
var remainingMinutesToday = 24*60-now;
if (momentInMinutes > remainingMinutesToday){
days = Math.floor((momentInMinutes-remainingMinutesToday) / (24*60));
if (days <= 1){
message += messages['tomorrow'];
} else if (days > 1){
message += messages['in'] + ' ' + (days) + ' ' + messages['days'];
}
} else {
console.log("Nothing." + momentInMinutes);
}
The problem is that days output after Math.floor is 1. But right now when I'm counting: momentInMinutes console output is 2803 and remainingMinutesToday is 763 so 2803-763=2040/1440=1,416666.... But the console shows 1 as an output of days and then it is always days <= 1 when it's not above 2 even when it should be "else if (days > 1)".
Thank you for all your help. PS: The last else is there just for debugging now because I can't get it to work.
Solution 1:[1]
Thank you. It's a downloaded plugin, I'm not good at JS but your point about Math.floor guided me to solve it.
A changed it to:
if (days < 1){
message += messages['tomorrow'];
} else if (days == 1){
message += messages['in'] + ' ' + (days) + ' ' + messages['day'];
} else if (days > 1){
message += messages['in'] + ' ' + (days) + ' ' + messages['days'];
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LM Rig |
