Typing fraction Value

Asked by Ravi

I want to type the float value 0.0000001 in textbox.
If i use the following code :

value = 0.0000001
type(str(value))

I am getting the output as 1e-07
I want value to be typed as 0.0000001

Same result by trying in following ways too
type(str(float(value)))
paste(str(value))
paste(str(float(value)))

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

type("%.7f"%value)

Revision history for this message
Ravi (gentlepersonravi) said :
#2

Thanks RaiMan
It worked.

Actually, I am using this type(value) in Handler Section.
This handler section is called in many places. And each time the value will be different. Either Integer or float (with different fractional digits such as 1e-06, 1e-07, 1e-10).

Here, using type("%.7f"%value) cannot work all time.
Is there any way to type integer and float (with different precision) .

Revision history for this message
RaiMan (raimund-hocke) said :
#3

ok, then you have to create a function, that gets a value (int or float), analyst it, dynamically build the format string and then return the formatted string.

Should all be easily possible with standard Python features.

Revision history for this message
Ravi (gentlepersonravi) said :
#4

Well.. I try to do that, I did not get any built-in function to convert float to string..
Again Its converting to exponent format(1e-05) like that..

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Ok, then you seem not to be familiar with Python scripting yet.

So you either have to learn how to setup user functions and how to do some more complex Python scripting,

... or you have to live with the above solution:
type("%.7f"%value)

and raise 7 to the maximum value possible and live with the trailing 0's in case.

Revision history for this message
Ravi (gentlepersonravi) said :
#6

yeah , Am new to python scripting.
I have tried with different options and found the below :

size = len(value)
dot_position = value.find(".")
my_string = str(float(value) + float("0." + "1".zfill(size - dot - 1)))

But it works not at all times.

If I use type(str(float(value) + float("0." + "1".zfill(size - dot - 1)))), it is working fine.
If I use my_string it is again using 1e-07 format.

I couldn't catch my wrong here.

Revision history for this message
Launchpad Janitor (janitor) said :
#7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.