PyQt4 change decimal digit in QLineEdit box - pyqt4

I want to change the decimal digit in QLineEdit box. Here is the code I write
self.le1= QtGui.QLineEdit()
self.le1.setValidator(QtGui.QDoubleValidator(1, 65535, 5))
From the documentation, I think it will make the input from range 1 to 65535 and can allow user to input 5 digits after decimal. But its not working. Can someone figure out the problem?

Related

Formatting number with a bunch of zeroes

Somewhat simple problem:
I need to turn a column A, which contains numbers with up to 1 decimal (20, 142, 2.5, etc.) to a string with a specific format, namely 8 whole digits and 6 decimal digits but without the actual decimal period, like so:
1 = 00000001000000
13 = 00000013000000
125 = 00000125000000
46.5 = 00000046500000
For what it's worth, the input data from column A will never be more than 3 total digits (0.5 to 999) and the decimal will always be either none or .5.
I also need for Excel to leave the zeroes alone instead of auto-formatting as a number and removing the ones at the beginning of the string.
As a makeshift solution, I've been using =CONCATENATE("'",TEXT(A1,"00000000.000000")), then copying the returning value and "pasting as value" where I actually need it.
It works fine, but I was wondering if there was a more direct solution where I don't have to manually intervene.
Thanks in advance!
=TEXT(A1*1000000,"0000000000000") I think that's what you mean.

Restrict floats to allotted padding while parsing as string

I would like to print a series of floats with varying amounts of numbers to the left of the decimal place. I would like these numbers to exactly fill a padding with blank spaces, digits, and a decimal point.
Paraphrasing the data and code I have now
floats = [321.1234561, 21.1234561, 1.1234561, 0.123456, 0.02345, 0.0034, 0.0004567]
for number in floats:
print('{:>8.6f}'.format(number))
This outputs
321.123456
21.123456
1.123456
0.123456
0.02345
0.0034
0.000457
I am looking for a way to print the following in a for loop assuming I don't know the amount of digits that will be to the left of the decimal place and the number of digits to the left never exceeds the padding which is 8 for this example.
321.1234
21.12345
1.123456
0.123456
0.02345
0.0034
0.000457
Similar questions have been asked about printing floating points with a certain width but the width they were talking about appeared to be the precision rather than the total number of character used to print the number.
Edit:
I have added a number to the end of the list for the following reason. The use of the specifier 'g' with 7 significant figures was recommended by attdona. This prevents the padding from being exceeded for numbers greater than or equal to 1 but not for numbers less than 1 with precision greater than 6. Using {:>8.7g} instead gives
321.1234
21.12345
1.123456
0.123456
0.02345
0.0034
0.0004567
Where the only one that exceeds the padding is the newly added one.
Use the General format type specifier g:
'{:>8.7g}'.format(number)
reference: https://docs.python.org/3/library/string.html#format-specification-mini-language
Update: For small numbers this format fails to align correctly. In this case you may adopt a mixed approach, but keep in mind that very small numbers will round to zero
for number in floats:
fstr = '{:>8.7g}'.format(number)
if len(fstr) > 8:
fstr = '{:>8.6f}'.format(number)
print(fstr)
for i in floats:
print('{:>8}'.format(f'{i:{8}.{8-len(str(int(i)))-1}f}'.rstrip('0')))
321.1235
21.12346
1.123456
0.123456
0.02345
0.0034

Convert number to tkinter color

Is there a simple way to convert a number into a tkinter color (#ffeedd).
I'm already setup to take the number and multiply it by 8 to give me a bit more color range leeway, and maybe even multiply it by 16 depending on just how much leeway I have to work with, not sure on how much leeway I will have yet... but I'm guessing I'll only be able to multiply by 8. How do I take that number and convert it over so I can use it with canvas.create_line((x,y), (x,y), fill = 'color'). I tried hex(number) but it just gives me back that color 0x0 doesn't exists... kinda figured that would happen but thought it would be worth a try.
a = 326
b = a * 8
canvas.create_line((x,y), (x,y), fill = b)
Ensure you have 3 or 6 hex digits. For instance:
frame.configure(background="#{0:06X}".format(0x808080))
The actual permitted set of color specfications is given in the GetColor
manual page.

Excel 2010 Formula to replace numbers

I have a list of results that may return a decimal value between 0 and 5. For business purposes I need to force Excel to replace the number as follows:
Any decimal value between 0 and 1 needs to show as the whole number 0
Any decimal value between 1 and 2 needs to show as the whole number 1
Any decimal value between 2 and 3 needs to show as the whole number 2
Any decimal value between 3 and 4 needs to show as the whole number 3
Any decimal value between 4 and 4.5needs to show as the whole number 4
Any decimal value between 4.5 and 5 needs to show the actual decimal value.
So, if the decimal value is 1.5, I want Excel to show it in the cell as 1. Or, if the decimal value is 4.5, I want excel to show it as 4.5.
I've tried using the following nested IF function (in this example the number to replaces is in cell L28):
=IF(L28>=4.5,L28,IF(L28<4.5>=4,"4",IF(L28=4,"4",IF(L28<4>=3,"3",IF(L28<2>=1,"2",IF(L28<1>=0,"0"))))))
However for some reason it works on values 4 or greater, but for anything <4 still shows 4, and I can't figure out why.
Should I be doing this in VBA instead?
Thanks in advance, and I'm hoping I explained this clearly...
This is why the FLOOR() function exists.
=IF(A1<=4.5,FLOOR(A1, 1),A1)

How to remove the decimal part from a float number that contains .000 in RDLC

I have a RDLC, contains a column weight, to show a float number.
If there's any decimal part, I have to show it.
If there's no decimal part, I shouldn't show x.000000
What do you suggest to do so?
Example
the number is 10.000001 then, I have to show the exact number, 10.000001
the number is 10.000000 then, I have to show 10
the number is 10.001000 then, I have to show 10.001
how can I do this in an expression of RDLC?
have you already tried this -
=Format(Fields!<<Field>>.Value, "#.########")
"#" will display the value if present.
You can also try
=Format(Fields!<<Field>>.Value, "D")
Also check - http://msdn.microsoft.com/en-us/library/ms252080%28VS.80%29.aspx
You could use conversion
CDbl(Fields!<<Field>>.Value)
Hope this helps
=FormatNumber(field,NoOfDigitsAfterDecimal)
http://msdn.microsoft.com/en-us/library/xfta99yt(v=vs.90).aspx

Resources