خرید بک لینک
I am working up a utility that will convert numbers
with decimal fractions to minutes and seconds; as in
angular measurements and time (hour) measurements

Since the Math.round method will not allow specification of places to round to
I have developed an approach for that. But it is depending on the use of
Math.pow(10, [specified places])

The places can be positive for powers and negative for roots to shift the decimal
point spec places to the right (+) or to the left (-)

However, I am getting very small values in the result of Math.pow:

In the code below I am trying to round second value to .1, so I get
a value like x.y.

This code represents the hoops I have to jump through to get the
intended result: 4.564983 -> 4 degrees 33 min 53.9 sec

The problem is marked <<<<****;

Is there a better builtin than Math.pow?

For info; in the code you will see sec = sec - sec%1
That will remove the decimal fraction from the number.
sec%1 is save in a separate variable.
4.5%1 == 0.5
4.5 - 4.5%1 == 4

I have not been able to get 4.565%0.01
to produce 0.065, for example.

Thanks for time and attention:
JK
Code:

// preceding code is determining the minutes
                if(Math.round(sec) == 60)
                  {
                  min++;
                  sec = 0
                  }
                else
                  {
                  // test case: 4.564983
                  sec = sec*Math.pow(10, 4);
                  sec = sec - sec%1;
                  sec = sec*Math.pow(10, -4)
                  sec = Math.round(sec*Math.pow(10, 1));
                  alert(sec) // -> 539
                  sec = sec - sec%1;
                  sec = sec*Math.pow(10, -1)
                  alert(sec) // -> 53.900000000000006 <<<<****
                  var tmp = sec%1;
                  sec = sec - tmp;
                  tmp = tmp*10;
                  tmp = tmp - tmp%1;
                  sec = sec+(tmp/10)
                  }

برچسب: نویسنده: آیلین رضوانی تاريخ: جمعه 15 دی 1396 ساعت: 16:52

صفحه بندی