find how many times a number appears inside a number

SGDK only sub forum

Moderator: Stef

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

find how many times a number appears inside a number

Post by matteus » Thu Oct 06, 2016 9:24 pm

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

Post by Grind » Thu Oct 06, 2016 10:25 pm

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

Post by matteus » Fri Oct 07, 2016 11:40 am

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.

Post Reply