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
#5
The error you're encountering is due to the fact that the value returned from the DMM is a string, and you're trying to format it as a float using the %.7f format specifier. To resolve this issue, you need to convert the string to a float before formatting it.

Here's an updated version of your code that converts the DMM value to a decimal number and formats it as a float:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import pyvisa
import time

rm = pyvisa.ResourceManager()
ps = rm.open_resource('ASRL8::INSTR')
ps.baud_rate = 115200
dmm = rm.open_resource('ASRL10::INSTR')
dmm.baud_rate = 115200

ps.write('VSET:1.0?')
ps.write('OUT:1')
ps.write('IOUT:1?')
time.sleep(3)
val = ps.query('IOUT?')
print("PS Current Reading:", val)

dmm.write('CONF:VOLTage:DC')
time.sleep(4)
number = float(dmm.query("MEAS?")) # Convert the DMM value to a float
print(number)
print("%.7f" % number) # Format the float value with 7 decimal places

rm.close()
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

By converting the DMM value to a float using float(dmm.query("MEAS?")), you can then format it as a float using the %.7f format specifier without encountering the TypeError.

Make sure that the DMM value you're receiving is a valid numerical value in scientific notation. If the DMM value contains any non-numeric characters or special characters, it may cause issues when converting it to a float.
buran write Jun-06-2023, 06:20 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply


Messages In This Thread
RE: issue with converting a scientific notation to standard notation - by rajeshgk - Jun-06-2023, 06:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 445 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 2,471 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  notation MCL169 8 1,542 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,139 Dec-06-2022, 11:09 AM
Last Post: mg24
  Music Notation editor; how to build the editor? direction to go? philipbergwerf 1 1,731 Jan-01-2022, 04:56 PM
Last Post: Larz60+
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,823 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  How to understand the byte notation in python3 blackknite 3 2,971 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,866 May-10-2020, 02:58 PM
Last Post: snippsat
  Simple question concerning python dot notation. miner_tom 1 1,935 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