# Help with Math and JavaScript

• Mar 11, 2014, 08:42
ketting00
Help with Math and JavaScript
I think I'm too stupid to solve this math equation myself.
Given:
Code:

`0.05 * 0.05 = 0.0025`
How do I make the result having greater value like 0.25, like they multiply integral number.

Was this possible at all and how do you calculate in JavaScript.

I want the numbers lesser than zero multiply with each another to having greater value not lesser.

Thanks
• Mar 11, 2014, 08:48
Mittineague
Sorry, I don't understand you.

.05 times .05 is .0025

So that result is correct. You want to purposely get an incorrect result?
• Mar 11, 2014, 09:06
ketting00
Sorry, I must be very stupid at math.
I want something like: 0.05 + 0.05 + 0.05 + 0.05 +0.05

It must multiply with integral number. A kindergarten could do this.
• Mar 11, 2014, 09:18
Mittineague
I don't know about that. When I was in kindergarten they didn't teach me decimals or fractions.

So what you want is
.05 times 5

Code:

```5        5      25 --    x  --  =  -- 100      1    100```

not
.05 times .05

Code:

```5          5        25 --    x  --    =  -- 100      100      10000```
• Mar 11, 2014, 09:25
ketting00
Thanks, that's more likely.

I calculate two time stamps. The first one is actually 0.0012208 seconds and the second is 0.0743354146 seconds.

I want to multiply them. It's impossible to have lesser value.
• Mar 11, 2014, 12:28
felgall
No programming language can multiply decimal fractions accurately because they all work with binary fractions.

If you want an accurate answer you need to make them all integers first and only convert back to a fraction at the end.
• Mar 11, 2014, 12:48
Mittineague
Doing something like
var result = ( (timestamp1 * 1000000000) * (timestamp2 * 1000000000) ) / 1000000000;

might give a more accurate result without losing precision, but I have to wonder why would timestamps ever need to be multiplied?
• Mar 11, 2014, 14:42
felgall
Quote:

Originally Posted by Mittineague
Doing something like
var result = ( (timestamp1 * 1000000000) * (timestamp2 * 1000000000) ) / 1000000000;

would give a wrong answer - you are multiplying by 1000000000000000000 but only dividing by 1000000000. The actual answer would be 1/1000000000 of what that calculation would produce.

The problem with converting to integers so as to not lose precision is in keeping track of what to divide by at the end.
• Mar 11, 2014, 14:57
Mittineague
:d'oh: right you are, thanks for catching that. The point I was focusing on (and obviously not giving much thought to the rest :blush: ) was why would one want to multiply timestamps?
• Mar 11, 2014, 18:16
ketting00
Thanks for help. I called it wrongly. It's speed not timestamps. Problem with all not native English speaker I guess.
• Mar 11, 2014, 18:52
ketting00
Addition: by speed, more multiple factors mean delay.
• Mar 11, 2014, 21:28
Mittineague
That makes more sense.

I would do something like
duration = end_timestamp - start_timestamp
for each thing you're timing. That would give you units of actual time to work with which you could convert to milli or micro seconds and should be a lot better to use IMHO