PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 9, 2022

[FIXED] How do I shift the decimal place in Python?

 August 09, 2022     decimal, python     No comments   

Issue

I'm currently using the following to compute the difference in two times. The out - in is very fast and thus I do not need to display the hour and minutes which are just 0.00 anyway. How do I actually shift the decimal place in Python?

def time_deltas(infile): 
    entries = (line.split() for line in open(INFILE, "r")) 
    ts = {}  
    for e in entries: 
        if " ".join(e[2:5]) == "OuchMsg out: [O]": 
            ts[e[8]] = e[0]    
        elif " ".join(e[2:5]) == "OuchMsg in: [A]":    
            in_ts, ref_id = e[0], e[7] 
            out_ts = ts.pop(ref_id, None) 
            yield (float(out_ts),ref_id[1:-1], "%.10f"%(float(in_ts) - float(out_ts)))

INFILE = 'C:/Users/kdalton/Documents/Minifile.txt'
print list(time_deltas(INFILE))

Solution

The same way you do in math

a = 0.01;
a *= 10; // shifts decimal place right
a /= 10.; // shifts decimal place left


Answered By - Andrew Rasmussen
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing