How I can specify two decimal point mask using CMFCMaskedEdit.
I want to validate/allow only integer with two decimal points.
Thanks,
Related
I've got a third party library that read values from laboratory scales. This library interface many scale models, each one with its own precision.
What I need to do in my C++ application (that uses that library) is to read the weight value from the scale (double format) and print it, taking into account the scale precision (so giving the user, reading that value, the information about scale precision).
So, connecting a scale with 2 decimals precision, the output should be for example: 23.45 g
Instead, connecting a scale with 4 decimals precision, the output should be for example: 23.4567 g
The fact is I don't know from the library the scale precision.
The function looks like the following:
double value = scale.Weight();
If I just print the double value, the output could be in the form of:
1.345999999999999
instead of:
1.346
Is there a way to understand the double precision so that the output shows the weight with the scale precision?
EDIT: scale precision goes from 0 to 6 decimals.
No. This information should be inside scale class as double type has "fixed" precision and you cannot change it. Also type precision and printed precision are two different things. You can use type that has infinite precision but show always 2 digits after dot etc. If scale do not have precision information you could do a helper class and hard code precision inside it then correlate it with some scale property or type.
I need to compress floating point numbers (4 bytes) to 1 byte(0 to 0xFF) to send to another device. The floating point numbers range from -100000.0 to 100000.0.
The other device will decode from 1 byte back to floating point numbers. How do it do it with minimum data loss?
Thanks, JC
One solution is to use quantization. Divide 100000 to 127 intervals. Send the interval number to which float belongs to and a sign in lowest or highest bit
In your case the interval = 787,4
For example, you have input like 100. Send 1. Input 1000,147732. Send 2
On the device you can restore number by its interval.
The easiest solution is to restore the number as a middle of the interval. For example, every float that belongs to the first interval will be restored as 393.7
If you have some stats for digits distribution and it's not uniform, you can play around it by changing the intervals length and quantize frequent floats more precisely
Why QLCDNumber numbers can't be centered when the number of digits is lower than the number of digits allowed in the parameters of QLCDNumber ?
Can I bypass this ?
As a workaround you can set the number of digits each time you set a new value :
ui->lcdNumber->display(value);
ui->lcdNumber->setDigitCount(QString("%1").arg(value).length());
Here QString("%1").arg(value).length() returns the number of digits in value. When you set it properly it would be aligned correctly.
The image below how all my records look in postgreSQL. I can't figure out why the geom field is so long, I can't make heads or tails of the number either. Is it the binary representation? Any help is appreciated
Geometry Types are stored in WKB (Well-Known Binary) form within PostGIS.
WKB form is a string of bytes that encode the information about this geometry. It holds information such as what kind of geometry is described (point, line, polygon, etc) as well as the actual information needed to represent the geometry itself.
The first byte in the stream identifies how the binary values are represented, either: NDR (Network Data Representation or XDR (eXtended Data Representation). The difference between the two encodings is byte order. NDR is little endian, which means that an unsigned integer – a 32 bit data type that encodes a nonnegative integer - stores the least significant byte first, while a double – a 64 bit double precision data type that encodes a double precision number using the IEEE 54 double precision format - stores the sign bit as the last byte. XDR is big endian, so the byte order is reversed.
The next component in the stream indicates the geometry type. Values from 1 through 7 indicate Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
If a geometry consists of multiple geometries, additional bytes indicate how many geometries there are.
The next byte component indicates the number of points in the first shape, followed by the X,Y coordinates of each of the points. For each additional shape, a byte indicates the number of points, followed by bytes defining each point’s coordinate values.
Alternatively, WKT (Well-Known Text) is a representation of geometry that would offer a better description for a human observer. WKT can be displayed by using the method ST_AsText in postGIS. There is a listing of examples of WKT representations for various geometry types in the postGIS documentation here.
If you would like more information about the WKB, see this helpful explanation of the representation.
So I have a CString which contains a number value e.g. "45.05" and I would like to round this number to one decimal place.
I use this funcion
_stscanf(strValue, _T("%f"), &m_Value);
to put the value into a float which i can round. However in the case of 45.05 the number i get is 45.04999... which rounds to 45.0 where one would expect 45.1
How can I get the correct value from my CString?
TIA
If you need a string result, your best bet is to find the decimal point and inspect the two digits after it and use them to make a rounded result. If you need a floating-point number as a result, well.. it's hopeless since 45.1 cannot be represented exactly.
EDIT: the nearest you can come to rounding with arithmetic is computing floor(x*10+0.5)/10, but know that doing this with 45.05 WILL NOT and CAN NOT result in 45.1.
You could extract the digits that make up the hundredths and below positions separately, convert them to a number and round it independently, and then add that to the rest of the number:
"45.05" = 45.0 and 0.5 tenths (0.5 can be represented exactly in binary)
round 0.5 tenths to 1
45.0 + 1 tenth = 45.1
don't confuse this with just handling the fractional position separately. "45.15" isn't divided into 45 and .15, it's divided into 45.1 and 0.5 tenths.
I haven't used c++ in a while but here are the steps I would take.
Count the characters after the Decimal
Remove the Decimal
cast the string to an Int
Perform Rounding operation
Divide by the (number of characters less one)*10
Store result in a float