Bizarre CRI glitch

I'm having an odd glitch happen while editing the CRi ex-parameter of some of my characters.  It's only happening with certain classes as well as a few weapons/armors.  Here's what's going on.


Take a look at this part of a character's status screen.  http://imgur.com/unitHzM


The "Chance" status is the CRI rate for the character.  It's suppose to be 15 for this character but it goes into some weird decimal and I don't know how to fix it.  He has one piece of equipment that increases his CRI rate by 1%, but removing it only makes the stat 14.0000000000000... ect.


Strangely, there is another character with a similar issue, but removing the armor for him does fix it.  I've looked into the coding for the classes and nothing is wrong, it's just a really weird bug that's occurring and I can't find a way to fix it.  Only some of the characters are experiencing this problem even though the CRI rate is implemented exactly the same for all of them.  Can anyone help?
Are you using an additional plugin that alters the way the status screen looks? I never really looked into MV, but I don't think there was a "critical strike chance" display by default.


Edit: Confused EX-paramters with SP-parameters, but they are still stored as floating point numbers. For example, a critical strike chance of 11% would be stored as  cri = 0.11  internally:


EX-parameters are not stored as integers internally, so it's completely possible to have a critical strike chance of 15.64211% for example. Due to the way those parameters are stored it is possible that operations like "increase by 1%" also result in a very small rounding error.


If the plugin that displays the result does not take care of that and rounds the displayed number accordingly this might lead to such an output.


If you find the code piece responsible for printing the chance to the status window, you should be able to use


Math.round( number )


to round the displayed number to an integer. Alternatively, you can use 


( number ).toFixed( x )


to create a text string of number rounded to x decimal places.
A am using some plugins, but I tried disabling them all and nothing has changed.  However what you recommended seems to have worked, Thanks!


I don't think an extra millionth of a chance to get a critical hit is going to matter in the grand scheme of things, but I'm still curious as to if there is a way to internally fix the rounding error.
Are you using an additional plugin that alters the way the status screen looks? I never really looked into MV, but I don't think there was a "critical strike chance" display by default.


Edit: Confused EX-paramters with SP-parameters, but they are still stored as floating point numbers. For example, a critical strike chance of 11% would be stored as  cri = 0.11  internally:


EX-parameters are not stored as integers internally, so it's completely possible to have a critical strike chance of 15.64211% for example. Due to the way those parameters are stored it is possible that operations like "increase by 1%" also result in a very small rounding error.


If the plugin that displays the result does not take care of that and rounds the displayed number accordingly this might lead to such an output.


If you find the code piece responsible for printing the chance to the status window, you should be able to use


Math.round( number )


to round the displayed number to an integer. Alternatively, you can use 


( number ).toFixed( x )


to create a text string of number rounded to x decimal places.





Do you think there are any other ways to fix this?  Again, your solution works pretty well but I think that somewhere in the code the tiny decimal difference is still being calculated.  Maybe there's a way to round the number as it's being calculated internally.  What do you think?
There is no extra calculation going on for the decimal difference.


The reason the error can appear is because applications represent numbers in the base-2 numeral system, since that's what practically all computers are optimized to work with. While 0.01 is easy to represent in the base-10 system, it becomes periodic when expressed in the base-2 system and has to be rounded.


Summing up multiple rounded values might just increase the error to a point where it is actually displayed when converting the result back into a decimal number.


You could improve the precision by choosing a representation that does not have to be rounded and change the calculations accordingly. However...


- The random number generation function is probably not that perfect to allow a "perfect" 15% chance anyway


- Since we are talking about randomness the actual number of critical strikes will vary wildly


- We are still far from talking about a millionth here (a millionth only has 5 zeros after the radix point 🙂 )


May I ask what you did exactly to fix the error? As I mentioned, I couldn't find the critical strike chance displayed anywhere in an empty project, so I'd really like to know where you found the code piece or which script you used. 🙂
There is no extra calculation going on for the decimal difference.


The reason the error can appear is because applications represent numbers in the base-2 numeral system, since that's what practically all computers are optimized to work with. While 0.01 is easy to represent in the base-10 system, it becomes periodic when expressed in the base-2 system and has to be rounded.


Summing up multiple rounded values might just increase the error to a point where it is actually displayed when converting the result back into a decimal number.


You could improve the precision by choosing a representation that does not have to be rounded and change the calculations accordingly. However...


- The random number generation function is probably not that perfect to allow a "perfect" 15% chance anyway


- Since we are talking about randomness the actual number of critical strikes will vary wildly


- We are still far from talking about a millionth here (a millionth only has 5 zeros after the radix point 🙂 )


May I ask what you did exactly to fix the error? As I mentioned, I couldn't find the critical strike chance displayed anywhere in an empty project, so I'd really like to know where you found the code piece or which script you used. 🙂

"Chance" is just the jargon my game is using for for the critical hit chance.  In the code that displays the status menu, I put a little space in between 2 of the normally displayed parameters to put this.


this.changeTextColor(this.systemColor());
this.drawText('Chance', x, y2, 200, 'left');
this.resetTextColor();
this.drawText(Math.round(this._actor.cri*100), x + 70, y2, 60, 'right');


If you take away "Math.round" you get the rounding error.
Do you think there are any other ways to fix this?  Again, your solution works pretty well but I think that somewhere in the code the tiny decimal difference is still being calculated.  Maybe there's a way to round the number as it's being calculated internally.  What do you think?



You'll have to round all the numbers yourself, since the game doesn't do that automatically.


It would be up to you to choose when numbers should be rounded to avoid rounding errors.


If the different is insignificant (ie: it doesn't affect the player if you don't show that 0.0000000000001), then you can just round it before it is drawn to the screen.

Original thread: https://forums.rpgmakerweb.com/threads/bizarre-cri-glitch.55661/