Member
Posts: 141
Threads: 20
Joined: 2010-08
What's the easiest way to get a program to round every value down as it calculates throughout the code? I've got my calculator, but it doesn't round down on the fly, only at the end where I've specified the function. Any easy way to do this? or will I have to create new variables and round them as the code is executed. If this is what has to be done, no wonder MS is so bloated.
Test Mushroom
Posts: 10,045
Threads: 1,506
Joined: 2008-06
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
IGN: GuavaCowboy
Server: Zenith
Level: 10x
Job: Jett
Guild: L>
Don't use typecasting to int as that does not always round down (negative numbers are rounded up - truncated). All programming languages have a "floor" function. I suggest you use that.
Member
Posts: 141
Threads: 20
Joined: 2010-08
I see what you did there, Hazzy.
Fiel, I've been using the following function to floor numbers:
function floor0(number) {
return Math.floor(number*Math.pow(10,0))/Math.pow(10,0);
}
But what do you do when you've got several places this needs to be enacted? For example, this is my Total LUK formula for MS calculations:
tLUKres = floor0((parseInt(inputbLUK)*maple_warrior) + (parseInt(inputbLUK)*(maple_warrior-1)*luk_percent));}
the way I see it, I'd have to calculate everything individually with new variables like this:
a_luk = floor0(parseInt(inputbLUK)*maple_warrior)
b_luk = floor0(parseInt(inputbLUK)*(maple_warrior-1)*luk_percent)
tLUKres = a_luk + b_luk
would that be the best way?
Thank you in advance.
Test Mushroom
Posts: 10,045
Threads: 1,506
Joined: 2008-06
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
IGN: GuavaCowboy
Server: Zenith
Level: 10x
Job: Jett
Guild: L>
Do it like the executable file does it - store both in a class. When you need the float version, call the float version. In your setter, set the float and the rounded version. Then wherever you need the variables, fetch the rounded or the float version as needed.
Member
Posts: 141
Threads: 20
Joined: 2010-08
errr you're gonna have to help me... I was sick when the "classes and structs" lecture was going on and I'm afraid that's a bit beyond my knowledge ^_^;;
Senior Member
Posts: 269
Threads: 15
Joined: 2010-07
What programming language are you using for this? I was going to guess Java, but the "function floor0(number)" syntax made me think otherwise. If it's Java, I can help you with classes. If not, I probably won't know the proper syntax. I can, however, go over the idea behind it. What I'm assuming Fiel had in mind was to make a class that will substitute for whatever type of variable you're using for number (I'm assuming an int or a float). The class will itself contain an int and a float as instance variables and will have getter/setter methods for them (e.g. class.getInt() and class.getFloat(), which will return the appropriate stored value). You could (and would probably want to) make other methods as well, such as class.add(), class.subtract(), class.multiply(), and class.divide() that perform the appropriate operation on both versions of the number (the int and the float) and then round the int. This way you'll be able to get at the unrounded float at any time, and the int should automatically round after every operation. The only real drawback is that you can't just use +, -, *, and / to do operations with it. But yeah, if you tell me what language you're using I might be able to be more specific with my help.