Rounding Numbers

Hello,

How can I round the value of a attribute based on its value. So if value is over 51 round up if value under 50 round down.

Ex

If attribute value is 220 round to 200
If attribute value is 951 round to 1000
If attribute value is 910 round to 900

Comments

  • ElfizmElfizm Member Posts: 489
    Make a rule,
    If value is equal to more then 249 change value to 200
    If value is more then 249 change value to 300

    Repeat process for how high you need to go.

    Working on a simplied version now, will see how I go.
  • ElfizmElfizm Member Posts: 489
    Scratch that,
    Here is what I did

    When touch is pressed
    Change "rounder" (has to be a integer Boolean) to "score"/100

    Change "score" to "rounder"*100


    How it works:
    Example:

    If your score is equal to 356
    You then are changing rounder to 356/100
    Since that's going to give you a decimal answer you have to use Interger Boolean for "rounder", as they automatically round up or down so they don't display any decimals.

    So it's going to say that the answe is 4, hence it rounded up from 3.56.

    Your then changing your score to 4 * 100 since you are wanting it rounded up in hundreds (which Is why you divided by 100 as well)

    That's it

    Hope it helps and is what your looking for.
  • games4fungames4fun Member Posts: 185
    Perfect !

    Thanks alot
  • games4fungames4fun Member Posts: 185
    Would you know how to have that final number rounded to a random percent between 10 percent to 50.

    So if final number was 1000. Then take 1000 and randomize it to a percent between 10 and 50. So lets say 17 percent so it would then be 170 and then round 170 to 200.

    Hopefully that makes sense.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2013
    Hello,

    How can I round the value of a attribute based on its value. So if value is over 51 round up if value under 50 round down.

    Ex

    If attribute value is 220 round to 200
    If attribute value is 951 round to 1000
    If attribute value is 910 round to 900
    You would use the mod function for this:

    If 50 < mod(game.value,100)
    .....change attribute game.value to ceil(game.value/100)*100
    Else
    .....change attribute game.value to floor(game.value/100)*100

    This is exactly how you can snap actors to a grid. If your grid spacing is 100, then the above rules will snap at every 100 pixels assuming you use self.position.X or self.position.Y as the attribute in place of game.value.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.