OK, I had to work through It but, yes, that thread did yield an answer. Much thanks. Please consider this question as closed.
New to Javascript and have made many searches for an answer. Lots of answers for rounding up including; .toFixed(2)
and .toPrecision(2)
. These solutions do not work for my problem.
I am looking to display to a two digit result for how It is displayed on screen so that if there are 10 days left It will display as, “10 Days left until this event” and the next day It will display as, “09 days left until this event”. As It is now I go from 10 days left to 9 days left. Accurate but It messes up my display formatting. I want to preserve a two digit number output regardless of calculation.
I don't know enough about javascript yet to try using a conditional to do this. A Conditional would count the output digits (one or two) and then say, if there are two digits do nothing else, if one “0” + theResuult.
I am guessing that there is an easier way to set this up with a formatting command?
What I have and how I got there:
var one_day=1000*60*60*24; // milliseconds
var d0 = new Date()
var d2 = new Date("October 1, 2015 12:00:00"); // “Some Event”
var diff2 = Math.abs(d0-d2); // difference in milliseconds
var res2 = Math.round(diff2/one_day);
res2 + " Days from: 10/01/2015 Some Event" + "\n"
This question is not a duplicate of another question. I am a beginner and I do not understand recursive calculations and how they may or may not related to anything else. I am seeking to determine the placeholder value and if It can be set. And of course, how.