# HTML code help?

I’ve got hold of some free ware with open HTML code. It’s purpose is to count key taps and average the frequency of taps into a beat per minute number for music timing.

The original code displyed the result down to hundredths of a beat per minute, or two decimal places. The relevant line of code is here:

(Math.round(bpmAvg * 100)) / = 100;

I wanted to round the displayed result to whole numbers, which I seem to have accomplished by editing the line to this:

Math.round(bpmAvg,0);

My question is: what is going on with the two 100’s? It looks as if bpmAvg is being multiplied by 100 and then divided by 100. That appears to be borne out by testing the two versions against one piece of music and getting the same results. Or nearly the same results, as the edited version doesn’t display the fractions. But I don’t know what that equal sign is doing in there, so maybe I’m wrong.

My other question is whether I am losing some degree of accuracy by eliminating those parts of the equation.

I am neither a programmer or a mathemetician, so I don’t really understand exactly what I’ve done.

BTW, if you need a program to manually calculate your musics’ bpm, or your heartbeat for that matter, by keyboard tapping, you can get it here:

**WARNING: going to this page downloads it and the beat counter program to your computer. The aim is to assure that internet traffic dous not affect the results – the calculations are performed locally. If you save the page, you are also saving the embedded program, and you can use it at any time whether you are on line or not. **

http://www.all8.com/tools/bpm.htm

Try this example step by step. Assume bpmAvg is set to 123.456789.

1. bpmAvg * 100 => 12345.6789

2)Math.round(bpmAvg * 100) => 12346

3)(Math.round(bpmAvg * 100)) / = 100 => 123.46

Basically the two 100s are there because Math.round rounds to the decimal point but here they wanted 2 decimal places. To do this they shifted it up 2 places, did the round, then shifted back.

And they have to jump through this hoop because the standard Javascript Math.round() method is rather basic. Other round() methods commonly allow you to specify the number of digits to round to, so it would simply be something like round(bpmAvg, 2).
I’m not sure how Math.round(bpmAvg,0) is working in your code, though. I am not a Javascript expert, but a bit of experimentation seems to indicate that the second parameter is simply ignored, so it’s equivalent to Math.round(bpmAvg).

I don’t think you’re losing any accuracy, other than the rounding that you know about.

The reason I made the change is that I googled HTML rounding and found a page saying that math.round works like this – math.round(variable, # decimals). Also, I tried taking the math.round statement out entirely, and the result was that the output displayed to 4 or 5 decimal places. So I figured 2 decimal places was some kind of default result for the math.round function.

But I was wrong. Having tried your experiment and removed the ‘,0’ parameter, I see you are right. I get the same whole number result.

I did not consider that the ‘100s’ were in the statement simply to increase the number of decimal places in the output.

Thanky you. I consider this question answerred.