Thread Tools Display Modes
07-19-12, 07:54 AM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Rounding down on Lua

Hey guys, quick question...

I've created a button which allows me to increase/decrease the height of ChatFrame by using OnMouseWheel.

The button also shows the height of the ChatFrame with OnSizeChanged:

Lua Code:
  1. self.text:SetText("Height: "..ChatFrame1:GetHeight())
It returns though with something like 280.00033324777.

While I appreciate it's accuracy lol, could someone give me a pointer on how I can round down the data that I get from GetHeight()?

Any help would be hugely appreciated .

Aanson
__________________
__________________
  Reply With Quote
07-19-12, 07:58 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Lua Code:
  1. self.text:SetText("Height: "..floor(ChatFrame1:GetHeight()))

http://wowprogramming.com/docs/api_categories#lua



On an unrelated note, all of the numbers behind the separator you're seeing are not due to accuracy, but due to the inaccuracy of how numbers are stored on a computer - at least non-integer numbers, but in lua, integers and non-integers are treated in the same way.

Last edited by Haleth : 07-19-12 at 08:01 AM.
  Reply With Quote
07-19-12, 11:57 AM   #3
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Cheers!

Cheers mate that's great
__________________
__________________
  Reply With Quote
07-19-12, 04:36 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I would suggest doing floor(ChatFrame1:GetHeight() + 0.5), so that if it returns 179.99999943743243 you will end up with 180, which is probably what you want.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-19-12, 05:04 PM   #5
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by Phanx View Post
I would suggest doing floor(ChatFrame1:GetHeight() + 0.5), so that if it returns 179.99999943743243 you will end up with 180, which is probably what you want.
Cheers Phanx lol. You've read my mind. That's perfect.

Aanson
__________________
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Rounding down on Lua

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off