Able to stop calculation returning 'e-002' at end?

This forum is currently in read-only mode.
  • It's extremely frustrating having my values randomly returning these

    because it makes trying to balance the values and growth really hard

    when it will be something like 0.16 and then 2.68e-002...

    I have no idea what the actual values it is ranging from are and I

    can't try and workout how to calculate that every single time it

    changes, as it does so continuously.

    I'd extremely appreciate if anyone knows how to stop this happening,

    it's an absolute nightmare and I've lost far too much time over this.

  • Also, sometimes I have a value and I add 0.1 every tick. If I print this value after 10 ticks, it will return 10.0000000000010 or something like that

    Here's a capx

    After more or less 5 seconds, it displays many zeroes

    Also, notice that I used "every 1 second" but the timer seems a bit random, why is that?

  • Use the "FormatDecimal()" system expression, it's output won't become 2.68e-002.


    FormatDecimal(0.0268, 4) -> "0.0268"


    That has to do with floating point precision.

    Short Answer:

    0.1 can't be exactly represented in binary, so a close approximation is used. When adding the number multiple times the inaccuracy grows. It is an issue with all computers. The number will not always be exact but it will be accurate to a certain number of digits, so the error is usually insignificant.

    Long Answer:

  • R0J0hound

    There's no FormatDecimal on C2 :/

    And thx for the explanation

  • Thank you very much :)

    It seems to work, however.....What on earth is this message about

    'Cannot add with integer and string. Operator had no effect' error

    that is caused when using FormatDecimal?

    As well as 'Cannot add with float and string. Operator had no effect'

    Now it won't let me add that variable in other calculations??

  • FormatDecimal, as ROJO showed in his example and can be seen in the wizard, outputs a string, not a number. There's no need to convert a number using FormatDecimal into a string and then keep on calculating with it. Just calculate with the number itself, not its human readable text form.

    btw, it isn't that hard to read. 2.68e-002 just means: shift the number 2.68 two decimal places to the right (2.68->0.268->0.0268)

    It's the same with everything else. 2.68e-003 = shift 3 decimal places to the right = 0.00268, etc.

    There's also the other way round. 1.5e+003 would mean, shift the number three decimal places to the left = 1500

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ahhh thank you, I hadn't realized that was meant to indicate it was being

    turned into a string, just thought that was to highlight what the end result was.

    Doing that would work if the number wasn't changing so radically as I mentioned,

    which makes that more misleading/distracting than anything.

    But I did get around it by as you said using the number itself in its

    continued calculation, and I instead made another variable for it to

    send the FormatDecimal result so I can keep an eye on it there :).

    Thank you both very much for your help again, I can finally continue

    moving forward with the project.

  • R0J0hound

    There's no FormatDecimal on C2 :/

    And thx for the explanation

    I have tried using FormatDecimal to format text into currency, and always get an error for unknown expression.

    Original format:

    "$" &(Balance/100) &"." &right("00" &Balance%100,2)

    has issues with displaying cents properly.

    Looking for a better solution, or advice on what may be causing the error.

  • seridras

    try this:

    "$" &int(Balance) &"." &right("00" &(Balance*100)%100,2)

  • Adding int() did the trick.

    I left off the (Balance*100)%100 since Balance was already storing cents in integer form (holdover from previous reference materials).


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)