WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Rounding down on Lua (https://www.wowinterface.com/forums/showthread.php?t=43748)

Aanson 07-19-12 07:54 AM

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

Haleth 07-19-12 07:58 AM

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.

Aanson 07-19-12 11:57 AM

Cheers!
 
Cheers mate that's great :)

Phanx 07-19-12 04:36 PM

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.

Aanson 07-19-12 05:04 PM

Quote:

Originally Posted by Phanx (Post 258456)
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


All times are GMT -6. The time now is 04:53 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI