Python Forum
issue with converting a scientific notation to standard notation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue with converting a scientific notation to standard notation
#1
I am reading the value from a DMM and the returned number is in Scientific notation. When I try to convert that number to get a decimal number, I get an error.

If I run the same script but cut and paste the reported DMM number into "number = 9.985660E-01" instead it works fine.
Are there some hidden characters I'm not seeing.? Is there a better way to convert to a standard decimal number from the DMM number?

Using number from DMM:
1 import pyvisa
2 import time
3 rm = pyvisa.ResourceManager()
4 # print(rm.list_resources())
5 ps = rm.open_resource('ASRL8::INSTR')
6 ps.baud_rate = 115200
7 dmm = rm.open_resource('ASRL10::INSTR')
8 dmm.baud_rate = 115200
9
10 ps.write('VSET:1.0?')
11 ps.write('OUT:1')
12 ps.write('IOUT:1?')
13 time.sleep(3)
14 val = ps.query('IOUT?')
15 print("PS Current Reading:",val)
16
17 dmm.write('CONF:VOLTage:DC')
18 time.sleep(4)
19 number = (dmm.query("MEAS?"))
20 print(number)
21 # number = 9.985660E-01
22 print("%.7f"%number) # Does not work using number in from DMM
23 rm.close()

PS C:\Users\thoma\Desktop\Python> c:; cd 'c:\Users\thoma\Desktop\Python'; & 'C:\Users\thoma\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\thoma\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '65078' '--' 'c:\Users\thoma\Desktop\Python\xxxx.py'
PS Current Reading: 00.925

9.349951E-01 #Value from DMM used in line 22

Traceback (most recent call last):
File "c:\Users\thoma\Desktop\Python\xxxx.py", line 22, in <module>
print("%.7f"%number) # Does not work using number in from DMM
~~~~~~^~~~~~~
TypeError: must be real number, not str
PS C:\Users\thoma\Desktop\Python>


1 import pyvisa
2 import time
3 rm = pyvisa.ResourceManager()
4 # print(rm.list_resources())
5 ps = rm.open_resource('ASRL8::INSTR')
6 ps.baud_rate = 115200
7 dmm = rm.open_resource('ASRL10::INSTR')
8 dmm.baud_rate = 115200
9
10 ps.write('VSET:1.0?')
11 ps.write('OUT:1')
12 ps.write('IOUT:1?')
13 time.sleep(3)
14 val = ps.query('IOUT?')
15 print("PS Current Reading:",val)
16
17 dmm.write('CONF:VOLTage:DC')
18 time.sleep(4)
19 number = (dmm.query("MEAS?"))
20 print(number)
21 number = 9.985660E-01
22 print("%.7f"%number) # uses number in line 21 and works fine
23rm.close()

PS C:\Users\thoma\Desktop\Python> c:; cd 'c:\Users\thoma\Desktop\Python'; & 'C:\Users\thoma\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\thoma\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '65120' '--' 'c:\Users\thoma\Desktop\Python\xxxx.py'
PS Current Reading: 00.930

9.346759E-01

0.9985660 # Converted number from line 21
PS C:\Users\thoma\Desktop\Python>
deanhystad write Jun-01-2023, 06:15 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
issue with converting a scientific notation to standard notation - by thomaswfirth - Jun-01-2023, 03:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 451 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 2,476 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  notation MCL169 8 1,550 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,150 Dec-06-2022, 11:09 AM
Last Post: mg24
  Music Notation editor; how to build the editor? direction to go? philipbergwerf 1 1,742 Jan-01-2022, 04:56 PM
Last Post: Larz60+
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,825 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  How to understand the byte notation in python3 blackknite 3 2,979 Feb-23-2021, 04:45 PM
Last Post: bowlofred
  Winsorized Mean and Standard Deviation Wheeliam 0 1,849 Jul-11-2020, 05:27 PM
Last Post: Wheeliam
  standard library modules chpyel 4 2,870 May-10-2020, 02:58 PM
Last Post: snippsat
  Simple question concerning python dot notation. miner_tom 1 1,938 Mar-24-2020, 05:20 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020