Reputation: 51241
How can I accomplish the following transformations with a regular expression in Python?
0.44 -> 44
0.7867 -> 78
1.00 -> 100
Upvotes: 0
Views: 141
Reputation: 5949
How about *100 and convert to int
t = lambda x: int (x*100)
t(0.44)
Upvotes: 0
Reputation: 27087
def twodigitint(x):
return int(100*float(x))
(or use round
instead of int
if you really want 0.7867->79)
Upvotes: 0
Reputation: 838176
Parse the input as a floating point number then multiply it by 100 and truncate to an integer:
result = int(float(s) * 100)
Upvotes: 5