View previous topic :: View next topic |
Author |
Message |
rog9001 Expert Cheater Reputation: 2
Joined: 22 Dec 2015 Posts: 214 Location: Jupiter
|
Posted: Sat Nov 26, 2016 10:19 am Post subject: How to input float value? |
|
|
what do I use to input a float value?
%x - Hex
%d - Decimal
%a - letter
. - any (but doesn't work)
which one do use?
Last edited by rog9001 on Sat Nov 26, 2016 11:03 am; edited 1 time in total |
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Sat Nov 26, 2016 10:42 am Post subject: |
|
|
Where did you get the idea %a is for strings?
If you're trying to print a number to the screen, use %f with string.format. It mostly follows the same rules as the C function printf with some minor changes (namely *, h, L, l, n, and p were removed and q was added). _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
rog9001 Expert Cheater Reputation: 2
Joined: 22 Dec 2015 Posts: 214 Location: Jupiter
|
Posted: Sat Nov 26, 2016 10:54 am Post subject: |
|
|
ParkourPenguin wrote: | Where did you get the idea %a is for strings? |
is not string. I meant letter. |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Wed Nov 30, 2016 2:37 am Post subject: |
|
|
Code: |
--converts a number into float
local function tofloat(x)
if x==0 then return 0 end
local s = 1
if x>=0x80000000 then
s = -1
x=x-0x80000000
end
local e = math.floor(x/0x800000)-127
local m=(x%0x800000)/0x800000+1
return s*(2^e)*m
end
--- test
a=tonumber('1000')
a=tofloat(a)
print(a)
5.8781724033436e-039 --- result
|
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Wed Nov 30, 2016 5:06 am Post subject: |
|
|
dwordToByteTable followed by byteTableToFloat is probably easier, but i doubt this is what rog9001 meant _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Wed Nov 30, 2016 9:10 am Post subject: |
|
|
from corona lab
Code: |
print( string.format( "%e, %E", math.pi, math.pi ) ) --> exponent: 3.141593e+00, 3.141593E+00
print( string.format( "%f, %g", math.pi, math.pi ) ) --> float and compact float: 3.141593, 3.14159
|
|
|
Back to top |
|
|
|