APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Problem with format output data - hypen mixed up with negative post and replies

Return to the Problem with format output data - hypen mixed up with negative thread
Login to post to this thread

Hyphen/dash instead of minus/negative for exponential numbers
James Mitchell
1 Posts

I had a problem reading my tracker data output with python. I solved the problem
For eksampel

1,6E-04 was formated with a dash/hyphen and not a negative  so python was reading it as a string that it could not float.

Just a fyi, hope someone changes the code.


Replies to Hyphen/dash instead of minus/negative for exponential numbers

Re: Hyphen/dash instead of minus/negative for exponential numbers -
Douglas Brown Avatar
Douglas Brown
375 Posts

Thanks for reporting this, James. Yes it's true that Tracker uses hyphen-minus (u002D) because that is the default "minus" char used by Java NumberFormat classes. Since you solved the problem and nobody else has ever reported it, we will likely do nothing unless others report the same issue.

Oddly, when I googled this issue I found this post
https://stackoverflow.com/questions/45630909/my-python-is-confusing-the-minus-with-dash-sign
in which a python user had exactly the opposite problem--their python would not read the u2212 char, only the u002D. Here is the accepted solution in that post:

"It's not a Python problem, the float numbers that you are passing begin with minus signs (−, unicode U+2212) instead of regular hyphens-minus symbols (-, unicode U+002D, the ones used by Python and most languages as "minus" sign). I'd guess it's because you copied the numbers from some document, since it is rather hard to type a Unicode minus sign with a keyboard.

The easy solution is to replace these signs with regular hyphens when you call the program in the command line. If you really need you program to work with these signs, you could use a function like this to parse the numbers instead of calling float:

def float_unicode(arg_str):
    return float(arg_str.decode("utf8").replace(u"\u2212", "-"))

However I wouldn't recommend this, as it just complicates the program more and most command line tools that work with numbers do not support this, so users generally won't expect your program to do so."

Doug

> I had a problem reading my tracker data output with
> python. I solved the problem
> For eksampel
>
> 1,6E-04
> was formated with a dash/hyphen and not a negative
>  so python was reading it as a string that it could
> not float.



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book