K7Q
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 5546 |
|
|
| 06 Aug 2015 01:49 PM |
lets say i have a number
like what math do i have to do to see what the percent of 52 into 1017 is? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 01:50 PM |
1017*.52
This is basic primary math... |
|
|
| Report Abuse |
|
|
FIares
|
  |
| Joined: 07 Nov 2010 |
| Total Posts: 641 |
|
|
| 06 Aug 2015 01:50 PM |
(52/1017) * 100
Check out my in-game scripting tutorial! [ 279086510 ] |
|
|
| Report Abuse |
|
|
K7Q
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 5546 |
|
|
| 06 Aug 2015 01:50 PM |
| i was wondering what was the most efficient for scripting? |
|
|
| Report Abuse |
|
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 06 Aug 2015 01:52 PM |
| new rule: you must complete 3rd grade to post here |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 01:52 PM |
| Most efficient? What? A simple calculator would laugh at such a simple math problem. |
|
|
| Report Abuse |
|
|
K7Q
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 5546 |
|
|
| 06 Aug 2015 01:54 PM |
| no i meant as in like which would cause the least amount of lag because a lot of math problems solved at once makes lag. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 01:57 PM |
^
No but seriously this way is the most efficient:
1017*.52
It only takes 1 operation, plus there's no dividing, and dividing is more expensive than multiplication. |
|
|
| Report Abuse |
|
|
| |
|
|
| 06 Aug 2015 01:59 PM |
Number=100
Number=number*.5-->half of number
print(Number) |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 06 Aug 2015 01:59 PM |
| the amount of lag that a simple math problem will cause is so insignificant |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:00 PM |
That ^ was meant for rayk999 qq
Dividing can be up to 2x (or more) expensive than multiplication, so my way probably is best since it's most compact. |
|
|
| Report Abuse |
|
|
K7Q
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 5546 |
|
|
| 06 Aug 2015 02:01 PM |
@warspy
1017 * .52 gives me 500 something so at the end I still have to divide by 100 |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 06 Aug 2015 02:04 PM |
The question is a bit misleading
Do you mean 52/1017 transformed into a percentage? Or what 52% of 1017 is? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:05 PM |
I feel nub, lol typo...
Number=100
Number=Number*.5-->half of number
print(Number) -->50 --Congrats 50% == .5 learn to convert percentage to decimal |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:05 PM |
t = tick() for i = 1, 10000 do local ans = 100*i end print(tick()-t)
t = tick() for i = 1, 10000 do local ans = 100/i end print(tick()-t)
>0.00050687789916992 >0.00057220458984375
See :D |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:07 PM |
> print(1017 * 0.52) 528.84
Looks like it's working to me. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:10 PM |
Lemme show you the diff between the 2 methods:
t = tick() for i = 1, 10 do for i = 0, 1, 0.001 do local ans = 100*i end end print(tick()-t)
t = tick() for i = 1, 10 do for i = 0, 1, 0.001 do local ans = i/100*100 end end print(tick()-t)
> 0.00049972534179688 --This was my method > 0.00084543228149414 --This was the divide then multiply method |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:10 PM |
If you are wanting to know the percentage is of 53 into 1017 is, then:
1017/52 -->19.56% |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:11 PM |
| That's because you're performing two different operations. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:12 PM |
@nQ I know, that's the different between the 2 methods.
However even alone division is longer than multiplication, but by very little. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2015 02:14 PM |
When using the brackets it's even longer:
> t = tick() for i = 1, 10 do for i = 0, 1, 0.001 do local ans = 100*i end end print(tick()-t)
t = tick() for i = 1, 10 do for i = 0, 1, 0.001 do local ans = i/100*100 end end print(tick()-t)
t = tick() for i = 1, 10 do for i = 0, 1, 0.001 do local ans = (i/100)*100 end end print(tick()-t) > 0.00052499771118164 > 0.00084543228149414 > 0.00084686279296875 |
|
|
| Report Abuse |
|
|
K7Q
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 5546 |
|
| |
|
|
| 06 Aug 2015 02:22 PM |
Wow sorry, I'm tired Flares was correct, the answer is
52/1017*100
-->5.11%
I'm going to bed, been scripting for to long today. Later. |
|
|
| Report Abuse |
|
|