views:

79

answers:

4

Heya all,

For a MMORPG World of Warcraft im trying to write a lib. Money in that games is stored as an Integer and in game currency is not an integer it's based of Gold, Silver and Copper coins.

Every 100 copper is 1 silver and every 100 silver is 1 gold.

Now I need to convert such an integer to the WoW Money format: for example

123123 should return: 23c 31s 12g

Anyone knows how to do this

+1  A: 

First of all devide 123123 to 10000. This gives you 12.3123. The whole number (12) is the gold number. The rest (after the delimeter) 3123 devide to 100 to get the silver. This gives you 31.23. Again the first part (31) is the silver and the rest (23) is your copper.

In C++ for instance, this algorithm will look like

int number = 123123;
int gold = number/10000; //this will give you the whole part because of the int type
number = number%10000; //this will make 'number' 3123
int silver = number/100; //this will get the silver
int copper = number%100; //this will get the copper
o15a3d4l11s2
+1  A: 

python:

def fmtGold(value):
    return "%sc %ss %sg"%(value%100,value/100%100,value/10000%100) 
TokenMacGuy
+1  A: 
  1. Divide integer by 10 000 (copper in gold), take the integer part, it will be the amount of gold.
  2. Take remainder from previous step. Divide by 100 (copper in silver), it will be the amount of silver.
  3. Take remainder from previous step. It will be copper.
Andrey
+4  A: 

C#:

int[] WoWMoney(int m)
{
        int[] result = new int[3];
        int copper = m % 100;
        m = (m - copper) / 100;
        int silver = m % 100;
        int gold = (m - silver) / 100;
        result[0] = copper;
        result[1] = silver;
        result[2] = gold;
        return result;
}
Ichibann