NCam : Can not enter float values after update to latest deb

More
03 Sep 2017 14:45 #98411 by newbynobi
Hallo Fern,

I just updated to the most recent release using package manager.
I am using German localized debian wheezy, using "," as decimal separator!

If I try to enter a value like >2,5< with the key pad, I get >25,000<
If I enter >2.5< I also get >25,000<
If I use the mouse and use only the buttons from the calculator the result is the same.

The only way to enter fractional values I found is to enter >5/2<, this way I get >2,500<

This happen since your change from Keypad to Calculator.

What can I do ?

Norbert

Please Log in or Create an account to join the conversation.

More
03 Sep 2017 15:28 #98412 by newbynobi
Hallo Fern,

if I commend out line 949 and 950 I get the correct value.
You replace in that lines the decimal_point with a dot, and in line 956 you doi search for decimal_point, but it can not be found any more, as it has been replaced!

Norbert

Please Log in or Create an account to join the conversation.

More
03 Sep 2017 16:01 #98414 by newbynobi
If I rework the compute part like this:
    def compute(self):
        qualified = ''
        temp = self.vkb_entry.get_text()
        while temp.count('(') > temp.count(')') :
            temp = temp + ')'
        self.opened_paren = 0
        self.save_edit = temp
#        if decimal_point != '.' :
#            temp = temp.replace(decimal_point, '.')
        temp = temp.replace('Pi', str(math.pi).replace(".",decimal_point))
        for i in('-', '+', '/', '*', '(', ')'):
            temp = temp.replace(i, " %s " % i)
        for i in temp.split():
            try:
                i = str(locale.atof(i))
            except:
                pass
            if i.isdigit():
                qualified = qualified + str(float(i))
            else:
                qualified = qualified + i
        try :
            return True, eval(qualified)
        except :
            return False, 0.0

It does work as expected. Please note, that I did change also the Pi part, as math.pi will return a value with a dot as separator, not the localized one.

Please check for inconvenience on other parts and feel free to use my changes as patch.

Norbert
The following user(s) said Thank You: eFalegname, FernV

Please Log in or Create an account to join the conversation.

More
07 Sep 2017 04:52 #98604 by FernV
Hi Norbert,

It seems that your decimal separator was simply dropped, not replaced with a dot.

I would like to understand why you had this issue and I have this short python script I would like you to test and post the result here.

File Attachment:

File Name: test.txt
File Size:1 KB


Here the result on my computer :
locale not loaded
decimal_point [. or ,] = .

base string = 2.5
replace decimal_point with a dot in 2.5
converted string = 2.5
float(converted string) * 2 = 5.000000
locale.atof(base string) = 2.500000
float(base string) = 2.500000
---------

locale loaded
('fr_CA', 'UTF-8')

decimal_point [. or ,] = ,

base string = 2,5
replace decimal_point with a dot in 2,5
converted string = 2.5
float(converted string) * 2 = 5.000000
locale.atof(base string) = 2.500000
cannot convert 2,5 to float with float(2,5)

Best regards
Fern
Attachments:

Please Log in or Create an account to join the conversation.

More
07 Sep 2017 20:52 - 07 Sep 2017 20:59 #98640 by newbynobi
Hallo Fern,

here are the German result:
gmoccapy@machinekit:~$ cd Downloads/
gmoccapy@machinekit:~/Downloads$ python test.py 

locale not loaded
decimal_point [. or ,] = .

base string = 2.5
replace decimal_point with a dot in 2.5
converted string = 2.5
float(converted string) * 2 = 5.000000
locale.atof(base string) = 2.500000
float(base string) = 2.500000
---------

locale loaded
('de_DE', 'UTF-8')

decimal_point [. or ,] = ,

base string = 2,5
replace decimal_point with a dot in 2,5
converted string = 2.5
float(converted string) * 2 = 5.000000
locale.atof(base string) = 2.500000
cannot convert 2,5 to float with float(2,5)
gmoccapy@machinekit:~/Downloads$ 

Seems strange, as I do get the same results as you, so I converted back my changes and tried again in NCam, with the same result, entering 2,5 gives me 25,000

With my changes all work as expected, I can also enter 2 * 2,5 getting 5,000 as result

Unfortunately I am not able at the moment to make a video of the screen :-(

Norbert
Last edit: 07 Sep 2017 20:59 by newbynobi.

Please Log in or Create an account to join the conversation.

More
07 Sep 2017 21:15 #98642 by newbynobi
Hallo Fern,

i went on checking, eval makes the difference:

just change the last try except to be:
try :
	print('locale.atof(base string) = %f' % (locale.atof(s)))
	print('float(base string) = %f' % (eval(str(locale.atof(s)))))
except :
	print('cannot convert %s to float with float(%s)' % (s, s))

Does this help to solve the issue?

Norbert

Please Log in or Create an account to join the conversation.

More
07 Sep 2017 23:06 #98647 by FernV
Hi Norbert,

Very strange indeed that you got 25,000 by entering 2,5 ...

I wonder why no one else reported the issue ...

Anyway since it works now, we will just leave it as is but if it happens again ?...

Best regards
Fern

Please Log in or Create an account to join the conversation.

More
08 Sep 2017 11:37 - 08 Sep 2017 13:30 #98664 by eFalegname
Hi Fern, sorry for not answering before, I've got plenty of backlogs, I didn't report the calculator issues because you said that it was a "work in progress" feature. A little video is coming to show you the issues I found in this update.
My regards
Floris
Last edit: 08 Sep 2017 13:30 by eFalegname.

Please Log in or Create an account to join the conversation.

More
08 Sep 2017 11:55 #98667 by newbynobi
Fern,

it is only solved with my changes to the code!
That is why i opened an issue in github, but you closed it!

I think it should remain oppened.

Norbert

Please Log in or Create an account to join the conversation.

More
08 Sep 2017 11:58 - 08 Sep 2017 11:58 #98668 by newbynobi
Hallo Floris,

could you check with my code change and report back?
IMHO your results could help Fern to solve that Problem.

Fern habe you tried from your side my code change?

Norbert
Last edit: 08 Sep 2017 11:58 by newbynobi.

Please Log in or Create an account to join the conversation.

Time to create page: 0.215 seconds
Powered by Kunena Forum