javascript数值计算得注意精度问题,Angularjs自制弹框

指令  directive('bsPopup', function ($parse) {          return {              require: 'ngModel',              restrict: 'A',              link: function (scope, elem, attrs, ctrl) {                  scope.$watch(function () {                      return $parse(ctrl.$modelValue)(scope);                  }, function (newValue) {                      if (newValue ==0) {                          $(elem).modal('hide');                          return;                      }                      if (newValue == 1) {                          $(elem).modal('show');                          return;                      }                  });              }          }      });

 <button class="btn btn-xs btn-warning" data-target="#myModal" data-toggle="modal" ng-click="sss()">弹框</button>          <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" class="modal fade" bs-popup="" ng-model="test"               id="myModal" style="display: none;">              <div class="modal-dialog">                  <div class="modal-content">                      <div class="modal-header alert-info">                          <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>                          <h4 id="myModalLabel" class="modal-title">弹框</h4>                      </div>                      <div class="modal-body">                          <button class="btn btn-info" ng-click="hhh()">测试</button>                      </div>                  </div>                  <!-- /.modal-content -->              </div>              <!-- /.modal-dialog -->          </div>

javascript 数值运算精度

       
使用javascript进行数值运算的时候要格外小心和注意,因为javas的浮点数的精度问题很严重,比如44444.1+4.2的值并不是想象中的44448.2,而是44448.299999999995
,同样对于乘法也是有很大的问题,如55.7*12的值不是668.4,而是668.4000000000001
;如果学了一些其他语言如C/C++,Java的都知道,虽然也存在浮点数精度的问题,但是对于这种比较简单的计算,他们还是能够应付自如的,不会出现这样的错误,所以说在javascript上对于一些小数的计算问题上还是得多注意,以免出现不知所谓的计算错误。

以为自己尝试的一些列子:

<html> <head>     <title>js测试用例</title> </head> <body >     <script type="text/javascript">         var c = 4444.1;         var d = 4.2;         var e = c + d;         document.write(e.toFixed(1) + " || ");//这个值是正确的4448.3         var a = 44444.1;         var b = 4.2;         document.write(a + b + "   ||   "); //这个值就错误了,变为44448.299999999995          var f = 55.7;         var g = 12;         document.write(f * g);  //这个值就错误了,变为668.4000000000001      </script> </body> </html>

对于这些问题,在自己可以预知结果的情况下,可以试用一下数学函数进行一些修正,如

1、四舍五入函数,

   Math.round()

2、取小于或等于值a的最接近整数函数

   Math.floor(a)

3、取大于或等于值a的最小整数函数

   Math.ceil()

4、使用数值对象自身的方法,

   e.toFixed(n)//e为数值,n为保留小数位数,方法为保留n位小数 

等等。。。。。

版权声明:本文为博主原创文章,未经博主允许不得转载。


Environment:

 

Oracle 10.0.2.1.0


Linux
kernal 2.6.18-92.el5PAE

ASSM Tablespace

Important: 9i and 10g’s root dba are
different

FILE HEADER:

status:0x4 root dba: 0x004001a1 chkpt cnt: 75 ctl
cnt:74 –9i point to
a cache block, cache block point to bootstrap$

FILE HEADER:

  status:0x4 root dba: 0x00400179 chkpt cnt: 75 ctl
cnt:74 –10g direct
point to bootstrap$, this object is no
more cached, that’s the why database can’t be started when SYSTEM
tablespace corrupted

Introduction

Each Oracle database has a SYSTEM tablespace, and
each SYSTEM tablespace has a Super Block which is file 1 block 1, the
Super Block has it’s struct KCVFH 676 bytes(10g)

struct kcvfh {

kcbh kcvfhbfh;    — Block Header, like every single
block, 20bytes

kccfhg kcvfhhdr;

krdba kcvfhrdb;   — point ot bootstrap$ RDBA
address, ONLY exist in FILE#1

kscn kcvfhcrs;    — SCN when datafile
created

ub4 kcvfhcrt;     –Timestamp when datafile
created

………}

Bootstrap$ including those main system dictionary,
such as OBJ$, and segment HDR address

What is Bootstrap: Bootstrap is a technique for
loading the first few instructions of a computer program into active
memory and then using them to bring in the rest of the
program.

What is Bootstrap in Oracle: In Oracle, Bootstrap
refers to loading of metadata (data dictionary) before we OPEN the
database. Bootstrap objects are classified as the objects (tables /
indexes / clusters) with the object_id below 56 as bootstrap objects.
These objects are mandatory to bring up an instance, as this contains
the most important metadata of the database.

After all, before analysis Oracle database structure,
we need to use Super Block to find the position of Bootstrap$, through
Bootstrap$ we can find those main system dictionaries, such as OBJ$,
C_OBJ$, TAB$, COL$, etc…

 

Bootstrap$ is created by script $ORACLE_HOME/RMDBS/ADMIN/sql.bsq, the position of this script is defined by a Hidden
Parameter _init_sql_file

SQL> @ GetHiddenParameter.sql

Enter value for par: init_sql_file

old   8:  where x.inst_id = userenv(‘Instance’) and
y.inst_id = userenv(‘Instance’) and x.indx = y.indx and x.ksppinm like
‘%_&par%’

new   8:  where x.inst_id = userenv(‘Instance’) and
y.inst_id = userenv(‘Instance’) and x.indx = y.indx and x.ksppinm like
‘%_init_sql_file%’

NAME        VALUE                ISDEFAULT 
ISMOD      ISADJ

——————— ————————————- —————— ——————- ———–

_init_sql_file   ?/rdbms/admin/sql.bsq  TRUE      
FALSE      FALSE

 

Before sql.bsq  there is another script $ORACLE_HOME/RMDBS/ADMIN/CreateDB.sql which called to create
Bootstrap$

 

Started to analysis 1) Super Block (set dba 1,1)
-> kcvfhrdb -> Dump File# 1 Block# 377
; 2) Trace Oracle database startup process

 

1) Super Block (set dba 1,1) -> kcvfhrdb ->
Dump File# 1 Block# 377

BBED> set dba 1,1

       DBA             0x00400001 (4194305
1,1)

 

BBED> map /v

File: /u01/app/oracle/oradata/orcl/system01.dbf
(1)

Block: 1                                    
Dba:0x00400001


Data File Header

 

struct kcvfh, 676 bytes                    @0      

    struct kcvfhbfh, 20 bytes               @0      

    struct kcvfhhdr, 76 bytes               @20     

     ub4 kcvfhrdb                            @96     

    struct kcvfhcrs, 8 bytes                @100    

    ub4 kcvfhcrt                            @108    

    ub4 kcvfhrlc                            @112    

    struct kcvfhrls, 8 bytes                @116    

    ub4 kcvfhbti                            @124    

    struct kcvfhbsc, 8 bytes                @128    

    ub2 kcvfhbth                            @136    

    ub2 kcvfhsta                            @138    

    struct kcvfhckp, 36 bytes               @484    

    ub4 kcvfhcpc                            @140    

    ub4 kcvfhrts                            @144    

    ub4 kcvfhccc                            @148    

    struct kcvfhbcp, 36 bytes               @152    

    ub4 kcvfhbhz                            @312    

    struct kcvfhxcd, 16 bytes               @316    

    word kcvfhtsn                           @332    

    ub2 kcvfhtln                            @336    

    text kcvfhtnm[30]                      
@338    

    ub4 kcvfhrfn                            @368    

    struct kcvfhrfs, 8 bytes                @372    

发表评论

电子邮件地址不会被公开。 必填项已用*标注