Place value jumps wildly! Possible bug
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Place value jumps wildly! Possible bug
Renpy 8.03.22090809 (Python 3) (Linux)
Is it only occurring with the python 3 versions because this persisted with previous python 3 versions of Renpy? Whenever a number vaule gets added after a few times when it comes to decimals it jumps way up to a point where it should not.
For example on my test. I added a value of 0.4 a couple of times (3 times) till it created that anomaly
As you can see from the image that is attached. In the meantime how do I fix this?
Is it only occurring with the python 3 versions because this persisted with previous python 3 versions of Renpy? Whenever a number vaule gets added after a few times when it comes to decimals it jumps way up to a point where it should not.
For example on my test. I added a value of 0.4 a couple of times (3 times) till it created that anomaly
As you can see from the image that is attached. In the meantime how do I fix this?
Re: Place value jumps wildly! Possible bug
This is actually correct, funny as it sounds. See https://docs.python.org/3.9/tutorial/floatingpoint.html for a deeper discussion of the reasons, but it has to do with how floating point numbers are stored internally.
I do wonder why the 2.7-based versions of RenPy don't do that, actually, but the correct solution is to limit the number of digits on display anyway.
Code: Select all
$ python
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.4 + 0.4 + 0.4
1.2000000000000002
>>>
$ python2
Python 2.7.18 (default, Jul 1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.4 + 0.4 + 0.4
1.2000000000000002
Re: Place value jumps wildly! Possible bug
What can I do to prevent that from happening. It really screws up with how stats look in the renpy project I'm working on.
Does anyone have a solution?
Does anyone have a solution?
Re: Place value jumps wildly! Possible bug
Just add a format specifier when actually displaying the number:
See https://peps.python.org/pep-3101/#format-specifiers for details. Or https://sahiljain444.medium.com/format- ... 1df860a6a4 for a more readable explanation.
Code: Select all
$ f = 0.4 + 0.4 + 0.4
"This line limits the [f:.2] to two digits after the decimal."
Re: Place value jumps wildly! Possible bug
I added that to one of my stats and it resulted in the following error: "Precision not allowed in integer format specifier"
example:
example:
Code: Select all
frame:
xpos 200
ypos 20
vbox:
spacing 5
text "Affection [affection_g1:.2]" size 45 color "000000"Re: Place value jumps wildly! Possible bug
You were trying to print an integer number as if it had decimals. Which is bogus so it's complaining. You can force it anyway: Replace ":.2" with ":.2f" and it will convert integers to float before trying to print them.
Who is online
Users browsing this forum: Google [Bot], Majestic-12 [Bot]
