Quantcast Math Help - Page 3 - WoWInterface
Thread Tools Display Modes
01-27-12, 09:48 PM   #41
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,671
Originally Posted by Grimsin View Post
Doesnt flooring cause it to round down?

Hmm and lets say it does not... somethings wrong somewhere because my end result is always off by a copper...
Dropping the decimal is the same thing as rounding down.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-28-12, 05:10 AM   #42
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
How about
Code:
local repairCost = x
repairCost = repairCost - discounts
print(format("%dG %2dS %2dC",
  repairCost/COPPER_PER_GOLD,
  math.mod(repairCost/COPPER_PER_SILVER, 100),
  math.mod(repairCost, 100)))
setting repairCost to 1234567.5444444 (123G, 45S, and 67.5444444 copper) outputs
"123G 45S 67C"

edit:: guess i will step through the code.
assuming repairCost is 1234567.5444444 and discounts is 0.

format("%dG %02dS %02dC" ...
-Basically, for every tag you have in your format string, you need to put a variable in the following parameters. so for every %d, it expects one parameter that can evaluate to an integer. Because I have 3 %d's, then I have 3 parameters following that string. The %02d tells the format command that the maximum amount of digits is 2. The 0 tells the command that if the amount of digits is less than 2, then pad the number with 0s. simply replace the %02d with %2d if you do not want to pad the numbers with a 0.

repairCost/COPPER_PER_GOLD
-1234567.544444 / 10000 = 123.4567544444

math.mod(repairCost/COPPER_PER_SILVER, 100),
-1234567.544444 / 100 = 12345.675444444
-12345.675444444 % 100 = 45.675444444 (modulos is the remainder. so 100 can go into 12345, 123 times equally with a remainder of 45. another example might be 5 % 3 = 2. saying that 3 can be divided into 5 only once equally, and has a remainder of 2.)

math.mod(repairCost, 100)
- same as above...
-1234567.544444 % 100 is 67.544444 because the remainder of 1234567.544444/100 is 67.544444.

And remember that %d asks for a integer, so it drops the decimal automatically.

Last edited by Xubera : 01-28-12 at 05:22 AM. Reason: walkthrough
  Reply With Quote
01-29-12, 11:27 AM   #43
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
btw i found this function on wowwiki. It worked perfectly.

Code:
function truncate(number, decimals)
    return number - (number % (0.1 ^ decimals))
end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-29-12, 10:36 PM   #44
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Don't you mean WoWPedia?
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
01-30-12, 06:43 AM   #45
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
Originally Posted by Grimsin View Post
btw i found this function on wowwiki. It worked perfectly.

Code:
function truncate(number, decimals)
    return number - (number % (0.1 ^ decimals))
end
I think you can even use this function to truncate, just don't ask about performance comparison between these two -the one here is probably milliseconds slower:
Code:
function truncate(number, decimals)
    return format("%."..decimals.."f", number)
end
Originally Posted by Torhal View Post
Don't you mean WoWPedia?
Probably, not all noticed the change, that the old wowwiki team left and made wowpedia under curse, many still use wowwiki because tbh, the transition was somewhat ninja-like...
  Reply With Quote
01-30-12, 12:27 PM   #46
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,851
Originally Posted by Vladinator View Post
Originally Posted by Grimsin View Post
btw i found this function on wowwiki. It worked perfectly.

Code:
function truncate(number, decimals)
    return number - (number % (0.1 ^ decimals))
end
I think you can even use this function to truncate, just don't ask about performance comparison between these two -the one here is probably milliseconds slower:
Code:
function truncate(number, decimals)
    return format("%."..decimals.."f", number)
end
More of the difference would be if you actually wanted a number returned or a string. Also string.format() rounds numbers to whatever decimal place you specify. It doesn't actually truncate them.



Originally Posted by Vladinator View Post
Originally Posted by Torhal View Post
Don't you mean WoWPedia?
Probably, not all noticed the change, that the old wowwiki team left and made wowpedia under curse, many still use wowwiki because tbh, the transition was somewhat ninja-like...
When WoWWiki joined Wikia.com, they had a problem with the site format Wikia was forcing on them, so they split off into WoWPedia. Both sites are still actively maintained.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-30-12, 01:05 PM   #47
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 792
Originally Posted by SDPhantom View Post
More of the difference would be if you actually wanted a number returned or a string. Also string.format() rounds numbers to whatever decimal place you specify. It doesn't actually truncate them.
Aye, it rounds, doesn't truncate... silly me!

Originally Posted by SDPhantom View Post
When WoWWiki joined Wikia.com, they had a problem with the site format Wikia was forcing on them, so they split off into WoWPedia. Both sites are still actively maintained.
That's true, but if the management left to wowpedia why did users stay on wowwiki? I mean, they don't allow custom tooltip modules and such and I think you need certain freedom when you wish to tailor a site for a specific game or what ever.
  Reply With Quote
01-30-12, 02:15 PM   #48
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,851
Originally Posted by Vladinator View Post
Originally Posted by SDPhantom View Post
When WoWWiki joined Wikia.com, they had a problem with the site format Wikia was forcing on them, so they split off into WoWPedia. Both sites are still actively maintained.
That's true, but if the management left to wowpedia why did users stay on wowwiki? I mean, they don't allow custom tooltip modules and such and I think you need certain freedom when you wish to tailor a site for a specific game or what ever.
It's still a publicly edited site and I'm guessing Wikia maintains it now. It wouldn't be a farfetched idea to say users from other Wikia sites could migrate over to WoWWiki along with people following links that are still pointing to the site.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Math Help

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