|
| 16 Aug 2012 08:31 AM |
So, I have a string like this: 12.5 (NOT A NUM-VALUE, IT'S A STRING) How could I take out the '.5' so I have
var1=12 var2=0.5 --or .5, that 0 doesn't matter.
I know it's something like string.find, or string.gmatch, I just need some help, as I am not very good with String Manipulation.
--TehChikenHater ლ(ಠ_ಠლ) |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Aug 2012 08:39 AM |
lolwut.
You fail bro.
--TehChikenHater ლ(ಠ_ಠლ) |
|
|
| Report Abuse |
|
|
| |
|
iAdobe
|
  |
| Joined: 22 May 2011 |
| Total Posts: 367 |
|
|
| 16 Aug 2012 08:46 AM |
local string = "12.5"
local newstring = string:find("12",1,true) |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:49 AM |
local var = "12.5"
var = tonumber(var) local var1 = math.floor(var) local var2 = (var-var1)
print(var1, var2) > 12 0.5 |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:54 AM |
Wow Crazyman32, I gotta give props for thinking of that. Thanks man. :3
-> Siggy pooped by the power of Ponies <- |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:54 AM |
| no probs, I've had to do it before. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:55 AM |
x = "12.5" a,b = string.find(x, "%p%d") print(string.sub(x,1,a-1)) |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:56 AM |
| I was thinking of that solution too, but mine works just as well. Good luck with whatever you're doing. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:57 AM |
Oh, you want the ".5" too?
Lemme figure it out for fun. Gimme a moment. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:58 AM |
| Actual regex string patterns will do the trick too, but straight-up math is actually faster for the computer to figure out |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:58 AM |
x = "12.5" a,b = string.find(x, "%p%d") print(string.sub(x,1,a-1), "0"..string.sub(x,a))
>12 0.5 |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 08:59 AM |
Thanks!
If anyone would like to know what i'm doing, i'm creating a timer to display how long someone has held a checkpoint or whatever you want to call it. :c And, I needed to do that, because if I have a number such as:
1230 (In seconds) if I divide that by 60, I get
20.5
So, 20 minutes, and 30 seconds, and I needed to beable to extract that 0.5, which is basically the decimal out. If you now know that this is what it's for, and think there is a better solution, feel free to post it.
-> Siggy pooped by the power of Ponies <- |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 09:01 AM |
Btw, if you're trying to keep good time, I suggest tracking actual time:
local start = time() while (IsOnCheckpointOrWhatever) do local fullTime = (time()-start)
-- fullTime is how long they've been there
wait() end |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 09:01 AM |
| It makes sense that your solution is faster, I just wanted to do something I haven't before. Again, good luck to all of you in whatever you do. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2012 09:07 AM |
The second one you gave me Crazyman32, will work much better for my script. Thank you so much! :D
-> Siggy pooped by the power of Ponies <- |
|
|
| Report Abuse |
|
|