Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to input float value?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
rog9001
Expert Cheater
Reputation: 2

Joined: 22 Dec 2015
Posts: 214
Location: Jupiter

PostPosted: Sat Nov 26, 2016 10:19 am    Post subject: How to input float value? Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sat Nov 26, 2016 10:42 am    Post subject: Reply with quote

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
View user's profile Send private message
rog9001
Expert Cheater
Reputation: 2

Joined: 22 Dec 2015
Posts: 214
Location: Jupiter

PostPosted: Sat Nov 26, 2016 10:54 am    Post subject: Reply with quote

ParkourPenguin wrote:
Where did you get the idea %a is for strings?


is not string. I meant letter.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Nov 30, 2016 2:37 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Wed Nov 30, 2016 5:06 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Nov 30, 2016 9:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites