rounding

How do I make a circle QLabel?

拥有回忆 提交于 2019-12-12 16:18:30
问题 I have a QLabel that i fill in red with the stylesheet, but the QLabel is rectangular, and I want a circle. I try to add border-radius, but it doesn't work, maybe because i put my QLabel in a formLayout. Is there a simple method to have a round QLabel by using stylesheet ? Thanks. EDIT : Using a picture seems more easier than doing this now. 回答1: Create an image that you use as a mask and set that on the label by calling setMask. As the documentation states: - Causes only the pixels of the

Hysteresis Round to solve “flickering” values due to noise

◇◆丶佛笑我妖孽 提交于 2019-12-12 16:08:20
问题 Background: We have an embedded system that converts linear positions (0 mm - 40 mm) from a potentiometer voltage to its digital value using a 10-bit analog to digital converter. ------------------------ 0mm | | 40 mm ------------------------ We show the user the linear position at 1 mm increments. Ex. 1mm, 2mm, 3mm, etc. The problem: Our system can be used in electromagnetically noisy environments which can cause the linear position to "flicker" due to noise entering the ADC. For example, we

How do I specify the rounding mode for floating point numbers?

爱⌒轻易说出口 提交于 2019-12-12 15:45:09
问题 I'd like to round floating point numbers to the nearest integer, going towards positive infinity when there is a tie for "nearest integer". use std::num::Float; fn main() { assert_eq!(-0.0, (-0.5).round()); // fails! } However, the docs for round say: Round half-way cases away from 0.0. I haven't seen anything that would allow me to change the rounding mode, but there's got to be some way, right? 回答1: It appears that the implementation of Float::round , at least for f32 and f64 , forward to

Having trouble rounding in c

≯℡__Kan透↙ 提交于 2019-12-12 13:02:54
问题 While trying to figure out how to round a float like 1.255 to the nearest hundredth, I found something interesting. I'm using gcc 4.4.5 on Debian 6. int x = (1.255 * 100) + 0.5; // gives me back 125 instead of 126. float y = (1.255 * 100) + 0.5; // gives me back 126.000000. Why is is that when I save to an int I get back 125 and not 126 ? In fedora when I save the above expression to an int I get back 126 . Is this a gcc bug in debian ? Any help would be greatly appreciated. Thanks. 回答1:

mysql decimal round

£可爱£侵袭症+ 提交于 2019-12-12 12:29:59
问题 I'm new to mysql and need some basic things. I need to round the decimals like : 21,4758 should be 21,48 0,2250 should be 0,22 23,0850 should be 23,08 22,9950 should be 22,99 I tried lots of thing but couldn't make it. Thanks. 回答1: DECLARE @old decimal(38, 10) DECLARE @p decimal(38, 10) SET @p = 21.4758 SET @p = @p * 100 SET @p = @p - 0.01 SET @p = ROUND(@p, 0) SET @p = @p / 100.0 SELECT @p 回答2: Try this: // round the value to two decimal places SELECT ROUND(<YOUR_FIELD>, 2) field FROM <YOUR

.NET: Decimal to rounded string

佐手、 提交于 2019-12-12 11:23:47
问题 If I have a decimal , how do I get a string version of it with two decimal places? This isn't working: Math.Round(myDecimal, 2).ToString("{0.00}"); 回答1: Don't use the curly brackets, they are for embedding a formatted value in a longer string using string.Format . Use this: myDecimal.ToString("0.00"); 回答2: Maybe i'm wrong, but i've tried myDecimal.ToString(); and it worked. 回答3: Assuming myDecimal is a System.Decimal , then Math.Round(myDecimal, 2).ToString(); will display two decimal digits

Rounding off floats with ostringstream

我与影子孤独终老i 提交于 2019-12-12 10:37:09
问题 I have an issue regarding conversion from float to c++ string using ostringstream. Here is my line: void doSomething(float t) { ostringstream stream; stream << t; cout << stream.str(); } when t has value -0.89999 it is round off to -0.9, but when it's value is 0.0999 or lesser than this say 1.754e-7, it just prints without round off. what can be the solution for this. 回答1: You need to set the precision for ostringstream using precision e.g stream.precision(3); stream<<fixed; // for fixed

How to round float 0.5 up to 1.0, while still rounding 0.45 to 0.0, as the usual school rounding?

你。 提交于 2019-12-12 08:56:08
问题 Appears that the default Python round(1 / 2) gives 0. How to round float 0.5 up to 1.0, while still rounding 0.45 to 0.0, as the usual school rounding? NOTE: Sorry for deleting and posting this again, but it was incorrectly marked as duplicate of another question. 回答1: It is actually currently considered proper to NOT blindly round *.5 up. Rather, it is proper to round *.5 to the nearest even number. Python 3 implements this "proper" form of "banker rounding", but a lot of other languages don

Problems with Rounding Floats in Python

别说谁变了你拦得住时间么 提交于 2019-12-12 08:46:19
问题 I'm having a problem with np.round, np.around where it is not rounding properly. I can't include code, because when I do it manually set the value (as opposed to use the my data), the return works, but here is the output: In [177]: a Out[177]: 0.0099999998 In [178]: np.round(a,2) Out[178]: 0.0099999998 In [179]: np.round(a,1) Out[179]: 0.0 What am I missing? The dtype of a is float32, do I need to change this? 回答1: Try creating np.float32(0.01) and you will see your answer. You are getting

How to deal with strange rounding of floats in PHP

断了今生、忘了曾经 提交于 2019-12-12 08:37:28
问题 As we all know, floating point arithmetic is not always completely accurate, but how do you deal with its inconsistencies? As an example, in PHP 5.2.9: (this doesn't happen in 5.3) echo round(14.99225, 4); // 14.9923 echo round(15.99225, 4); // 15.9923 echo round(16.99225, 4); // 16.9922 ?? echo round(17.99225, 4); // 17.9922 ?? echo round(25.99225, 4); // 25.9922 ?? echo round(26.99225, 4); // 26.9923 How would you work around this? 回答1: Welcome to IEEE754, enjoy your stay. Use bc or gmp