Rounding Numbers

hopscotch
help
helpwithcode

#1

Alright- Problems

I want to have a value round up to the next whole number. So say I have this equation

ValueA= 15 * 1.15 ^ ValueB

Now, this makes ValueA equal 17.25 when ValueB increases by one, then when ValueB is 2, it then equals 19.8375.
Is there any way just to make it equal 18, 20, etc.?
Thanks
-Paz


Rounding Numbers. How do I do that?
#2

I believe the Repeat block rounds to a whole number, so try:

Repeat (value)
Increase Value (new value) by 1
end

Set Value (value) to (new value)


Tell me if it doesn't work.


#3

Ooh there is!
Use my tutorial >>>>>>>HERE<<<<<<<
except change 100 to 1.


might or might not work... :frowning:

#4

This post was flagged by the community and is temporarily hidden.


#5

I find 'smaller than' Whens kinda unreliable at times, so I that works better for me :wink:


#6

This post was flagged by the community and is temporarily hidden.


#7

@Intellection74 and @CreativeCoder

So...
I'ma break it...
I'm making a cookie clicker, one that uses the browser game's algorithm. This is why I need rounding. Because the equation is:
Price= B * 1.15 ^ A
Where B is base cost
Where A is Amount of buildings.
So, just to check, is this what you give me will work?


#8

I'm not entirely sure. What I gave is a modified version that was used to check if a number was a decimal. I could play around with it if you like.


#9

This post was flagged by the community and is temporarily hidden.


#10

That would be helpful. I'm not the greatest at block coding. (oddly enough, I succeed in Almost anything else XD)


#11

Alright. I'll test it out with a few test numbers such as .25, .5, .75, etc.


#12

Here's some pictures Just a few plans for stuff, and what is happening with the math:



#13

@pazon123 Okay, I think this method is sound, with a couple changes.

The Repeat block actually rounds down, so before the Repeat you'd need "Increase Value (value to be rounded up) by 1".

Screenshots coming soon.


#14

k.. I'll see if the code you'll show works, Thanks!


#15

In this, "rounded#" would be what you need rounded, "incr. var" is a new value.

You don't need the first Set Value, that's just to get a first decimal number.

Of course, tell me if this doesn't work.


#16

This post was flagged by the community and is temporarily hidden.


#17

It works!
...
I wanna Ask though
If I go through this Code again, do I have to set incr var to 1 agaiN?


#18

Hmm...as in when in the game would you go through the code again?


#19

Yes

I'm experimenting it with it now... but it seems to go up 2, go down 1, then go up more, but if I don't set it to 1, The rounded# get's too high of a number too fast. Should I just set incr var to rounded?

Because in the real game, here's the first four costs
15>18>20>23
In What it is now:
15>17(thats ok)>36


#20

Try it, I suppose. I'm going to look at old posts to see how your rounded# acts with other things. One minute...