Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Decimals reading Python

Programming


Tags
solved

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-05-2015   -   Original Discussion by Board27
Board27's Unix or Linux Image
Board27 Board27 is offline
Registered User
 
Join Date: Oct 2014
Last Activity: 13 November 2017, 2:18 AM EST
Posts: 45
Thanks: 21
Thanked 0 Times in 0 Posts
Decimals reading Python

Hello,

i'm new in python. Consider that i have this function that read me some data from a serial :


Code:
def GetData():
  line = open(serialx).read()
  hash = line.find("#")
  when = line[:hash]
  count = line[hash+1:-1]
  # print when, count, line
  return (float(when), int(count))

it gives me the result with tre digits like 301 300 301 etc.. how i can have more decimals (and precision reading) to achieve a result of ex 3000001 eventually using another counter too like +001 -001?

Thank you

Regards

Last edited by Scrutinizer; 09-05-2015 at 07:48 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 09-05-2015   -   Original Discussion by Board27
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 20 November 2017, 9:27 AM EST
Posts: 1,673
Thanks: 49
Thanked 641 Times in 601 Posts
Hi Board27,

This is the information I have parsed so far.
return (float(when), int(count)) will give you a tuple comprised of a float and an int, but you say -- "it gives me the result with tre digits like 301 300 301 etc ..."
I do not understand, there is no tuple but a number. You say -- "how i can have more decimals (and precision reading)", however there are no decimals in your post.
Somewhat you want to make the number three hundred and one (301) into the number three millions and one (3000001)

A decimal would be 0.301 and if you want to add seven digits of precision it will become 0.3010000, never 0.3000001

Please, could you clarify a bit more your request? Perhaps, could you consider posting the content of the file serialx?

Last edited by Aia; 09-05-2015 at 03:54 PM.. Reason: Adds request for clarification and serialx file
The Following User Says Thank You to Aia For This Useful Post:
Board27 (09-05-2015)
Sponsored Links
    #3  
Old Unix and Linux 09-05-2015   -   Original Discussion by Board27
Board27's Unix or Linux Image
Board27 Board27 is offline
Registered User
 
Join Date: Oct 2014
Last Activity: 13 November 2017, 2:18 AM EST
Posts: 45
Thanks: 21
Thanked 0 Times in 0 Posts
Thanks, floating points numbers did it.

Thanks

regards
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Python Reading Individual files and Regex through them metallica1973 Programming 4 11-19-2013 06:38 PM
Python reading from a file jaldo0805 Programming 0 06-26-2013 05:22 PM
Python reading from a file jaldo0805 Programming 0 06-26-2013 05:13 PM
Help Reading XML files in Python: Urgent dcfivesixfive Shell Programming and Scripting 2 05-12-2009 08:25 AM
convert Regular decimals to Packed decimals mgirinath Shell Programming and Scripting 2 09-20-2008 10:27 AM



All times are GMT -4. The time now is 08:40 PM.