Student code problem with adding .1

My student hasn’t finished his code for the unit 4 project, but he’s having a problem that I have been unable to solve. When adding 0.1 to the user GPA using the up button, the number jumps around in unexpected ways. Can anyone help with this? Here is a link to the project:

@erogers I did some digging and the solutions here I found won’t work in the AppLab environment. I will pass this on to the curriculum team. Look for a response soon.

1 Like

App Lab is based on Javascript. Javascript only has floating point numbers. That means that small approximations in representing numbers can build up as you do multiple operations. I think there is something about that in the curriculum somewhere.

Anyway, you can unwind some of those approximations with a little math. Math.round(userGPA*10)/10

In some problem domains like money where we want to have a fixed number of decimal places we use an integer for internal representation and add the decimal place when we display those numbers. Since App Lab doesn’t have integers we can’t do that here.

The language used for guiding telescopes is Forth. Forth doesn’t even have floating point numbers because telescopes need precision. Tiny numbers are scaled up with great forethought so they don’t all end up being zero or something outrageously inaccurate.