Doing Eval(Math. ) is returning only int numbers?

I'm trying to get a string, and execute the code within it using eval(Mystring) and then storing this value inside a game variable to display using a game message.

Problem is, it's returning only int values(For Math.PI, it returns 3 instead of 3,14...., for Math.LN2, it returns 0 instead of 0,693...). How could I get the full number that should be returning when I write Math.something?
Can you show us your exact code?
There are several places where the engine intentionally changes to integers for a lot of reasons. And there are ways around those conversions, but they depend onwhat exactly you did. For example game variables are by default only storing integers, but you can store other values if you know how.
eval is working correctly and returning a float. It's the assigning it to a variable that's causing it to truncate the fractional part.

If you're putting it into a variable, do this:
Code:
$gameVariables._data[id] = eval(string); $gameVariables.onChange();

so it won't convert numbers to integers.
Depends on how you are doing it. If you are using the Game_Variables.prototype.setValue method (i.e. $gameVariables.setValue(3, Math.PI)) it's possible the value is getting rounded down.
Note the Math.floor() in the code below.

Code:
Game_Variables.prototype.setValue = function(variableId, value) {
   if (variableId > 0 && variableId < $dataSystem.variables.length) {
      if (typeof value === 'number') {
         value = Math.floor(value);
      }
   this._data[variableId] = value;
   this.onChange();
   }
};
Thanks for everyone's answers!

eval is working correctly and returning a float. It's the assigning it to a variable that's causing it to truncate the fractional part.

If you're putting it into a variable, do this:
Code:
$gameVariables._data[id] = eval(string); $gameVariables.onChange();

so it won't convert numbers to integers.
It seems to have work perfectly, ty Shaz!

Original thread: https://forums.rpgmakerweb.com/threads/doing-eval-math-is-returning-only-int-numbers.93608/