In iOS, there are often situations where precision is distorted, and some common ways to prevent distortion are summarized below.1. Double Turn number precision distortionDouble money = 89.99;NSNumber *moneynum = [NSNumber Numberwithdouble:money];NSLog (@ "%@", moneynum); At this time output 89.9899999999999;Using NsdecimalnumberMoneynum = [Nsdecimalnumber decimalnumberwithstring:[nsstring stringwithformat:@ "%f", money]];NSLog (@ "%@", moneynum); Output 89.99 at this time2.
to this problem is as follows:-(void) testdecimalnumber { nsdecimalnumber* n1 = [Nsdecimalnumber Decimalnumberwithstring:[nsstring stringWithFormat:@ "%f", D1]]; Nsdecimalnumber* n2 = [Nsdecimalnumber decimalnumberwithstring:[nsstring stringwithformat:@ "%f ", D2]]; Nsdecimalnumber* n3 = [N1 DECIMALNUMBERBYMULTIPLYINGBY:N2]; NSLog (@ "%@", number);}You can convert a float, double to an object of type Nsdecimalnumber in the calculation. You can perform operations of + 、-、 *,/
// by modifying the time Poke can be on Log and the Debug Time modification of information displayService timestampsdebug datetime msec localtime show-timezoneService Timestampslog datetime msec localtime show-timezone// Select the time for which service needs to be modified Poke650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/50/wKiom1e73Gvz9JnVAAAPaE95tWQ106.png "style=" float: none; "title=" 1.png "alt=" Wkiom1e73gvz9jnvaaapae95twq106.png "/>// Select whether the type of time is
When writing code on demand today, it is occasionally found that when you set the variable type float and double calculations under Linux,The results are not the same.Requirement: Set value = Incoming Value * 10 * 122.88/1000;Case: Set value = 1666*10*122.88/1000= 2047.1808When set to float, the code:#include Execution results (inconsistent with the results to be obtained):[Email protected] test_float_compare]# gcc test_float_double_diff.c-o test_float_double_diff_1666[[email protected] Test_flo
{int i,k;k=a[0]>b[0]?a[0]:b[0]; K is the number of digits of the largest number of digits in a and Bfor (i=1;i{a[i+1]+= (A[i]+b[i])/10; If there is rounding, the advanced bitA[i]= (A[i]+b[i])%10;} Calculate the current bit number, note: This statement cannot be exchanged with the previous one.if (a[k+1]>0) a[0]=k+1; Fixed the number of digits of the new A (a+b up to one carry only)else a[0]=k;return 0;}Four, high-precision subtractionint gminus (int a[],int b[]);//calculate a=a-b, return symbol
Most languages encounter precision problems when dealing with floating-point numbers, but in JS it seems particularly serious to look at an examplealert(45.6*13);It turned out to be 592.800000000001, and of course the addition would have this problem.So this is JS's mistake?Of course not, your computer is doing the correct binary floating-point arithmetic, but the problem is that you enter the decimal number, the computer is binary operation, the two are not always converted so good, sometimes g
This article is divided into three parts:1, JS digital precision loss of some typical problems2, the reason for the loss of JS digital precision3. Solutions (one object + one function)First, JS Digital precision loss of some typical problems1. Two simple floating-point numbers added0.1 0.2 0.3 // trueLook at the results of Java operations2. Large integer operation9999999999999999 10000000000000001 // true var 9007199254740992 1// trueThe 16-and 17-digit numbers are equal, plus 1 are equal.3. T
}Both the ④float class and the Double class both override the corresponding Equals method, judging whether the same belongs to a float object or double object, if not directly returning false, and if you continue to compare the corresponding numeric size .The source code of JDK1.8 is as follows:The 1.Float class overrides the Equals method:1 Public Boolean equals (Object obj) {2 return instanceof Float) (Floattointbits ((Float) obj.) = = Floattointbits (value)); 3 }The 2.Double class ov
of fields. Here's the first animated GIF show I've ever done, and you can comment out all nonclustered fields. I used column mode editing, not just commenting out the fields:
Create all Indexes
When you use more than a union statement for a field:
Comment out the list of fields for the GROUP by clause
Test Query Results
I have to use the external connection "OUTER" to list all the customers, because not all of the customer's ZIP code has a corresponding ZIP code in the local table. I can
Keyboard and mouse, it can be said that we Win7 64 flagship version of the computer indispensable accessories, although many Win7 flagship notebook computers are equipped with touchpad, but in contrast, we mouse operation is indeed much faster, more accurate, so in general, the use of computer friends will be configured with a mouse. So what if the mouse is not good to do? Is there any way to adjust it? The following, small series on the detailed introduction, how in our Win7 flagship computer t
JS format amount, optional whether with thousand points, optional retention accuracy, but also found on the Internet, but the use of no problem
Copy Code code as follows:
/*
The values are rounded and formatted.
@param num Value (number or string)
@param number of decimal places to keep cent
@param whether the Isthousand need to be 0: not required, 1: required (numerical type);
A string @return format, such as ' 1,234,567.45 '
@type
In high-precision ad conversion, the requirements of the power supply is often very large, if there are multiple ad conversion, you can use automatic digital zeroing to reduce the error caused by power fluctuations.
First, the 1-channel grounding, the 2-channel connection to the reference power vcc,3 channel needs to measure the value, the conversion begins, the first Test 1 channels, get N0, test 2 channels of NR, the Signal Channel 3 is NR
The actual voltage VX=VR (nx-n0)/(Nr-n0), the result
also very simple, because the computer due to floating point accuracy error is not very large, so through a roundn function can be removed from the tail error.
>> delta = 5-4.8;
Delta = ROUNDN (delta,-2);
X=-1:delta:1
x =
-1.0000 -0.8000 -0.6000 -0.4000 -0.2000 0 0.2000 0.4000 0.6000 0.8000 1.0000
In addition, how can we make delta = = 0.2 set up. Truncation using Roundn is a method, but the truncated digits must
Using the "to show precision" option results in cumulative calculation effects, making your data less accurate over time. You can use this option only if you are sure that the display precision will keep the data accurate.
1, click the Office
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.