## find how many times a number appears inside a number

SGDK only sub forum

Moderator: Stef

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

### find how many times a number appears inside a number

I've a u16 from 1 to 200, I display the number as 3 images from 1 to 9. So if I had 211 it would be 3 image [2] [1] [1].

The problem is I'm struggling to do the calculation to work out how many 100, 10s and 1s are in the u16!

I thought the below code would work but it doesn't :/ can someone help me?

Code: Select all

mod = fix16ToRoundedInt(intToFix16(GameVariables.ConcertEnergy) % 100);
intTemp1 = fix16ToRoundedInt(intToFix16((GameVariables.ConcertEnergy) - FIX16(mod) / 100));
mod = fix16ToRoundedInt(intToFix16(GameVariables.ConcertEnergy % 10));
intTemp2 = fix16ToRoundedInt(intToFix16((GameVariables.ConcertEnergy - FIX16(mod)) / 10));

Grind
Very interested
Posts: 68
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

### Re: find how many times a number appears inside a number

the modulus opoerator won't work right with fixed point numbers, have to convert to int first.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

### Re: find how many times a number appears inside a number

Grind wrote:the modulus opoerator won't work right with fixed point numbers, have to convert to int first.
Thanks grind I knew something wasn't quite right.