CN104461506A - Algorithm for solving repeating decimal problem in Java Script - Google Patents
Algorithm for solving repeating decimal problem in Java Script Download PDFInfo
- Publication number
- CN104461506A CN104461506A CN201410624768.6A CN201410624768A CN104461506A CN 104461506 A CN104461506 A CN 104461506A CN 201410624768 A CN201410624768 A CN 201410624768A CN 104461506 A CN104461506 A CN 104461506A
- Authority
- CN
- China
- Prior art keywords
- javascript
- decimal
- result
- infinite loop
- algorithm
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
The invention relates to the technical field of Java Scripts, in particular to an algorithm for solving a repeating decimal problem in a Java Script. The algorithm includes the steps that 1, all numbers and operational characters needing operation are obtained; 2, results in normal arithmetical operation and results in Java Script operation are analyzed; 3, the abnormal results which are terminating decimals for normal arithmetical operation and repeating decimals appearing in Java Script operation are expanded; 4, operation is carried out step by step, the expanded operation results are synchronously reduced to obtain operation results. The problem that due to the particularity of Java Script languages, the results are the terminating decimals for normal arithmetical operation and the repeating decimals appearing in Java Script operation is solved, the accuracy of the operation results in the Java Script is improved, and the algorithm can be widely applied to various kinds of digital operation in the Java Script.
Description
Technical field
The present invention relates to JavaScript technical field, be specifically related to a kind of algorithm solving infinite loop decimal in JavaScript.
Background technology
JavaScript a kind ofly has a client-side scripting language of relative safety based on object and event-driven, is a kind of regime type, weak type, literal translation formula script based on prototype; Also be a kind of script being widely used in client Web exploitation simultaneously; Be commonly used to add dynamic function to HTML (subset of standard generalized markup language) webpage, such as respond the various operations etc. of user.
Due to the singularity of its language, to a certain extent the operation result between numeral and its be there are differences with normal mathematical way operation result, affect precision and the accuracy of result, thus affect result and the Consumer's Experience of business processing.
Summary of the invention
The technical matters that the present invention solves is to provide a kind of algorithm solving infinite loop decimal in JavaScript.For user provides one simpler and more direct, efficient, more accurate operational method.
The technical scheme that the present invention solves the problems of the technologies described above is:
Comprise following step:
Step one, acquisition will carry out various numeral and the operational symbol of computing;
Step 2, analyze the result of computing in normal mathematical operation and JavaScript;
Step 3, normal operation is finite decimal and in JavaScript, occurs that the abnormal results of infinite loop decimal expands;
Step 4, separate operations, synchronously reduce the operation result after expanding;
Finally export operation result.
In described step one, obtain the various digital parameters in business processing, by its business demand, digital parameters is coupled together with different operational symbols, composition arithmetic expression.
In described step 2, arithmetic expression step one formed carries out computing in JavaScript, preserves its operation result, then carries out calculating result with normal mathematical way, is analyzed by two kinds of operation results.
In described step 3, the result of two kinds of computing comparative analyses is carried out judgement process, if two kinds of operation results are consistent, then without the need to carrying out step 4, direct Output rusults; If normal mathematical operation result is finite decimal, and occurs infinite loop decimal in JavaScript after computing, expansion is carried out to operation result and preserves.
In described step 4, separate operations, narrows down to the figure place of former expansion by operation result after expansion in step 3, exports operation result.
The present invention is by carrying out judgement branch process to the result of computing in JavaScript, abnormal result is had first to expand to normal mathematical operation, and then separate operations reduces, export last precise results, solve the accuracy problem of JavaScript computing between numbers.
Accompanying drawing explanation
Below in conjunction with accompanying drawing, the present invention is further described:
Accompanying drawing is the inventive method FB(flow block).
Embodiment
As shown in Figure 1, the present invention specifically comprises following step:
Step one: obtain the digital parameters in business processing, by its business demand, digital parameters is coupled together with different operational symbols, composition arithmetic expression;
Step 2: with the mode saving result of normal mathematical operation, then be kept at the result of computing in JavaScript, analyzes the result of contrast two kinds of computings;
Step 3: the result of two kinds of computing comparative analyses is carried out judgement process, if two kinds of operation results are consistent, then directly export operation result, computing terminates; If normal mathematical operation result is finite decimal, and in JavaScript, after computing, there is infinite loop decimal, the n power of 10 is multiplied by doubly to the operation result calculating infinite loop decimal, for ensureing its accuracy, the value of n is greater than 4 as far as possible, carries out expansion and preserves;
Step 4: with step 3 separate operations, narrows down to the figure place of former expansion by the operation result after expansion, export operation result, can obtain the most accurate operation result.
Claims (7)
1. solve an algorithm for infinite loop decimal in JavaScript, it is characterized in that:
Comprise following step:
Step one, acquisition will carry out various numeral and the operational symbol of computing;
Step 2, analyze the result of computing in normal mathematical operation and JavaScript;
Step 3, normal operation is finite decimal and in JavaScript, occurs the exception of infinite loop decimal
Result expands;
Step 4, separate operations, synchronously reduce the operation result after expanding;
Finally export operation result.
2. the algorithm solving infinite loop decimal in JavaScript according to claim 1, it is characterized in that: in described step one, obtain the various digital parameters in business processing, by its business demand, digital parameters is coupled together with different operational symbols, composition arithmetic expression.
3. the algorithm solving infinite loop decimal in JavaScript according to claim 1, it is characterized in that: in described step 2, arithmetic expression step one formed carries out computing in JavaScript, preserve its operation result, carry out calculating result with normal mathematical way again, two kinds of operation results are analyzed.
4. the algorithm solving infinite loop decimal in JavaScript according to claim 2, it is characterized in that: in described step 2, arithmetic expression step one formed carries out computing in JavaScript, preserve its operation result, carry out calculating result with normal mathematical way again, two kinds of operation results are analyzed.
5. the algorithm of infinite loop decimal in the solution JavaScript according to any one of Claims 1-4, it is characterized in that: in described step 3, the result of two kinds of computing comparative analyses is carried out judgement process, if two kinds of operation results are consistent, then without the need to carrying out step 4, direct Output rusults; If normal mathematical operation result is finite decimal, and occurs infinite loop decimal in JavaScript after computing, expansion is carried out to operation result and preserves.
6. the algorithm of infinite loop decimal in the solution JavaScript according to any one of Claims 1-4, is characterized in that: in described step 4, separate operations, operation result after expansion in step 3 is narrowed down to the figure place of former expansion, exports operation result.
7. the algorithm solving infinite loop decimal in JavaScript according to claim 5, is characterized in that: in described step 4, separate operations, operation result after expansion in step 3 is narrowed down to the figure place of former expansion, exports operation result.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410624768.6A CN104461506A (en) | 2014-11-06 | 2014-11-06 | Algorithm for solving repeating decimal problem in Java Script |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410624768.6A CN104461506A (en) | 2014-11-06 | 2014-11-06 | Algorithm for solving repeating decimal problem in Java Script |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104461506A true CN104461506A (en) | 2015-03-25 |
Family
ID=52907618
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410624768.6A Pending CN104461506A (en) | 2014-11-06 | 2014-11-06 | Algorithm for solving repeating decimal problem in Java Script |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104461506A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107832058A (en) * | 2017-10-31 | 2018-03-23 | 北京小米移动软件有限公司 | Data processing method and device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120030661A1 (en) * | 2010-07-30 | 2012-02-02 | Apple Inc. | Observation and analysis based code optimization |
CN103064720A (en) * | 2011-09-09 | 2013-04-24 | 微软公司 | Profile guided jit code generation |
CN103529773A (en) * | 2013-09-18 | 2014-01-22 | 国家电网公司 | Automatic conversion method for behavior control scripting language |
CN104115120A (en) * | 2012-02-07 | 2014-10-22 | 微软公司 | Transferring program execution from compiled code to interpreted code |
-
2014
- 2014-11-06 CN CN201410624768.6A patent/CN104461506A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120030661A1 (en) * | 2010-07-30 | 2012-02-02 | Apple Inc. | Observation and analysis based code optimization |
CN103064720A (en) * | 2011-09-09 | 2013-04-24 | 微软公司 | Profile guided jit code generation |
CN104115120A (en) * | 2012-02-07 | 2014-10-22 | 微软公司 | Transferring program execution from compiled code to interpreted code |
CN103529773A (en) * | 2013-09-18 | 2014-01-22 | 国家电网公司 | Automatic conversion method for behavior control scripting language |
Non-Patent Citations (3)
Title |
---|
朱羽佳: "javascript浮点数运算问题分析及解决方法", 《HTTP://WWW.CNBLOGS.COM/YJZHU/P/3755159.HTML》 * |
脚本之家: "JavaScript浮点数运算 精度问题", 《HTTP://WWW.JB51.NET/ARTICLE/20267.HTM》 * |
脚本之家: "JavaScript浮点数运算精度问题", 《HTTP://WWW.JB51.NET/ARTICLE/20267.HTM》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107832058A (en) * | 2017-10-31 | 2018-03-23 | 北京小米移动软件有限公司 | Data processing method and device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
MY195917A (en) | Blockchain-Based Data Processing Method And Device | |
CN102541874B (en) | Webpage text content extracting method and device | |
EP4276584A3 (en) | Content-aware energy savings for web browsing utilizing selective loading priority | |
CN103389895A (en) | Method and system for generating front end page | |
MX365897B (en) | Similarity determination method, device, and terminal. | |
CN110991171B (en) | Sensitive word detection method and device | |
IN2015DE00812A (en) | ||
WO2016058156A1 (en) | Method and apparatus for aligning form elements of web page | |
CN104699667A (en) | Semantic dictionary-based improved word similarity calculating method and device | |
CN103246641A (en) | Text semantic information analyzing system and method | |
CN104461506A (en) | Algorithm for solving repeating decimal problem in Java Script | |
CN107871128B (en) | High-robustness image recognition method based on SVG dynamic graph | |
CN106897052A (en) | APK file compression method and device | |
CN106775826B (en) | Method and system for loading code file by annotation mode | |
CN106339381B (en) | Information processing method and device | |
CN112199626A (en) | Dynamic form generation method based on DSL layout engine | |
CN105279076A (en) | Webpage test method and terminal | |
IL227332B (en) | System and method for automated generation of web decoding templates | |
US9092406B2 (en) | Creating a text-editable web page using a word processor | |
CN111078188A (en) | Floating point data processing method and device in JavaScript operation and electronic equipment | |
CN107436927B (en) | Application method and system of UI component | |
CN105204864A (en) | JavaScript extension function and method | |
CN102929777B (en) | Network application method of testing and test macro | |
CN106776886A (en) | A kind of Webpage body matter abstracting method and device | |
CN104391897A (en) | Method and device for previewing JSP (Java Server Page) based on label |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20150325 |
|
WD01 | Invention patent application deemed withdrawn after publication |