Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Adding .1 with a for loop?

Community Beginner ,
Nov 10, 2015 Nov 10, 2015

I attempted to add increment of .1 to a value using a for loop, but the for loop did not add to the value in precise increments.

So, instead of getting  .1,.2,.3,.4, etc, I got the following when I traced the loop:

0

0.1

0.2

0.30000000000000004

0.4

0.5

0.6

0.7

0.7999999999999999

0.8999999999999999

0.9999999999999999

This throws my code off completely because it causes the loop to run one unnecessary time and the value returned causes other functions to work improperly. Please advise on how to fix this.  I notice that this is not a problem once you get to .25.

TOPICS
ActionScript
408
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 10, 2015 Nov 10, 2015

use .toFixed(1); after the value

Translate
Enthusiast ,
Nov 10, 2015 Nov 10, 2015

use .toFixed(1); after the value

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2015 Nov 10, 2015

Thanks for prompt response.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 10, 2015 Nov 10, 2015
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines