JS float type conversion and take n decimal places

javascript variables are weakly typed, all the variables are declared as var, the type conversion process there is no java so convenient, it is through

parseInt (variable), parseFloat (variable) and other methods to carry out the type conversion. Note: No parseDouble (variable) This type of conversion, because

regardless of javascript in the single-precision and double precision float double, a small number of variables everything that is float, so to get the n decimal places, use the method toFixed (n) to get.

For example:
var f = 2.56556;
f.toFixed (2);

Preferable to the variable f 2 after the decimal, if not float type, but also the need for type conversion (parseFloat (variable name)), to obtain by this method.

分类:Web 时间:2010-03-27 人气:252
分享到:
blog comments powered by Disqus

相关文章

  • java data type conversion Integer String Long Float Double Date 2010-07-24

    1 How to convert integer string String int? A. There are two ways: 1). Int i = Integer.parseInt ([String]); or i = Integer.parseInt ([String], [int radix]); 2). Int i = Integer.valueOf (my_str). IntValue (); Note: The string converted to Double, Floa

  • java data type conversion Xiangjie 2010-03-29

    Java data types are divided into three categories, namely, the Boolean type, character and numeric type, which are divided into numeric integer and floating-point type; relative to the data types, Java variable of type Boolean boolean; character char

  • java data type conversion 2010-12-05

    Some beginners may encounter friends JAVA JAVA data type conversion between the distress, for example, integer and float, double type conversion between integer and String conversion between types, as well as processing, display timing of the problem

  • struts2 type conversion study summary 2010-08-23

    Examples are given below 1, the preparation of input form input.jsp, the code below <body> <h2><font color="red"> Use commas to separate the two points </font></h2> <s:form action="pointConverter"> &

  • Javascript interception of decimal places and rounded 2010-05-05

    round method Role: to return and give expression to the nearest integer value. Syntax: Math.round (number), will be option number parameter is rounded to the nearest integer value. Note: If the number is greater than equal to the fractional part of 0

  • JavaScript Type Conversion 2010-09-27

    As a dynamic language, JavaScript's type conversion is always carried out in silence, not many people know. However, understanding the type of conversion is a good understanding of JavaScript JavaScript in the basic course. The conversion mechanism i

  • javascript numeric type conversion problems in the 2010-05-13

    Yesterday, a project, identified a problem, (0.3). ToString () value is not "0.3" and "0.30000000001", and (0.2). ToString () value is "0.2", very much puzzled. In that the string "0.3", so can only be (0.3). ToFixe

  • Javascript rounding decimal (n decimal places reserved rounded) 2010-10-28

    Javascript rounding decimal (n decimal places reserved rounded) First, problems arise: Own coding, javascript encountered in 3.21 * 3 = 9.629999999999999 phenomenon Second, Baidu, 1. ..... He is more clever will not add 0 after decimal <script> var

  • in javascript how to get only two decimal places? 2009-08-16

    Cases sum = parseFloat (8.99) + parseFloat (7.50); Wait until the value is: 16.4900000002 How to get only two decimal places? <script language="JScript"> Number.prototype.toFixed = function (num) ( / / Re-structure toFixed method, IE5.0 +

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.176 (s). 12 q(s)