# print("-5.3e - 10"*"2") doesnt work :/

8 messages
Open this post in threaded view
|

## print("-5.3e - 10"*"2") doesnt work :/

 Here (http://www.lua.org/pil/2.4.html) you can find an example of using strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform arithmetic on a string value)... I use Lua 5.1. Generaly I want to use it to calculate strings (fe. "5+1+4" => print("5+1+4"+"0") should give 10 but it doesnt work.. :( Thanks for help Oldrich Svec
Open this post in threaded view
|

## Re: print("-5.3e - 10"*"2") doesnt work :/

 On Thursday 27 April 2006 3:15 pm, Oldrich Svec wrote: > Here (http://www.lua.org/pil/2.4.html) you can find an example of using > strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform if this is scientific notation (-5.3 x 10^-10), remove the spaces around the '-' and it works ok. > arithmetic on a string value)... I use Lua 5.1. > Generaly I want to use it to calculate strings (fe. "5+1+4" => > print("5+1+4"+"0") should give 10 but it doesnt work.. :( use: function calcstring (s)     local f = loadstring ("return "..s)     return f and f() end print (calcstring ("5+1+4")) => 10 -- Javier attachment0 (205 bytes) Download Attachment
Open this post in threaded view
|

## Re: print("-5.3e - 10"*"2") doesnt work :/

 In reply to this post by Oldrich Svec On 4/27/06, Oldrich Svec <[hidden email]> wrote: > Here (http://www.lua.org/pil/2.4.html) you can find an example of using > strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform > arithmetic on a string value)... I use Lua 5.1. > Generaly I want to use it to calculate strings (fe. "5+1+4" => > print("5+1+4"+"0") should give 10 but it doesnt work.. :( In this case, "-5.3e - 10" isn't recognized as a number.  Try "-5.3e-10"*"2", which is recognized as a number. "5+1+4"+"0" doesn't work because "5+1+4" is not a number. You would have to do print("5"+"1"+"4"+"0") instead. -- Zachary P. Landau <[hidden email]>
Open this post in threaded view
|

## Re: print("-5.3e - 10"*"2") doesnt work :/

 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Zachary P. Landau wrote: [...] > In this case, "-5.3e - 10" isn't recognized as a number.  Try > "-5.3e-10"*"2", which is recognized as a number. True, but those spaces are actually in the documentation, which makes the provided example not work --- a typesetting issue? - -- +- David Given --McQ-+ "If you're up against someone more intelligent |  [hidden email]    | than you are, do something insane and let him think | ([hidden email]) | himself to death." --- Pyanfar Chanur +- www.cowlark.com --+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.orgiD8DBQFEUU4Yf9E0noFvlzgRAp4rAKCXBOITxBFjzu2YtcY8XjwitmxAjACcDoxW PkVT8NoDj248mPhWReyXS04= =VWq0 -----END PGP SIGNATURE-----
Open this post in threaded view
|

## Re: print("-5.3e - 10"*"2") doesnt work :/

 In reply to this post by Zachary P. Landau-4 And is there a way how to calculate fe. such string "(5+1+4)^(3+4)/5" so I dont need to change it into "5"+"1"..... The problem is that I get the formulas in string form... and I dont want to add " " all the time manualy Oldrich Svec ______________________________________________________________ > Od: [hidden email] > Komu: "Lua list" <[hidden email]> > CC: > Datum: 27.04.2006 23:43 > Předmět: Re: print("-5.3e - 10"*"2") doesnt work :/ > > On 4/27/06, Oldrich Svec <[hidden email]>wrote: > > Here (http://www.lua.org/pil/2.4.html) you can find an example of using > > strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform > > arithmetic on a string value)... I use Lua 5.1. > > Generaly I want to use it to calculate strings (fe. "5+1+4" => > > print("5+1+4"+"0") should give 10 but it doesnt work.. :( > > In this case, "-5.3e - 10" isn't recognized as a number. Try > "-5.3e-10"*"2", which is recognized as a number. > > "5+1+4"+"0" doesn't work because "5+1+4" is not a number. You would > have to do print("5"+"1"+"4"+"0") instead. > > -- > Zachary P. Landau <[hidden email]> >
Open this post in threaded view
|

## Re: print("-5.3e - 10"*"2") doesnt work :/

 In reply to this post by Javier Guerra Giraldez Hups. I overlooked your answer.. I will try it.. hopefully it will work ;) Thanks for help Oldrich Svec ______________________________________________________________ > Od: [hidden email] > Komu: Lua list <[hidden email]> > CC: > Datum: 27.04.2006 23:30 > Předmět: Re: print("-5.3e - 10"*"2") doesnt work :/ > > On Thursday 27 April 2006 3:15 pm, Oldrich Svec wrote: > > Here (http://www.lua.org/pil/2.4.html) you can find an example of using > > strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform > > if this is scientific notation (-5.3 x 10^-10), remove the spaces around > the > '-' and it works ok. > > > arithmetic on a string value)... I use Lua 5.1. > > Generaly I want to use it to calculate strings (fe. "5+1+4" => > > print("5+1+4"+"0") should give 10 but it doesnt work.. :( > > use: > > function calcstring (s) > local f = loadstring ("return "..s) > return f and f() > end > > print (calcstring ("5+1+4")) => 10 > > > -- > Javier > >