JS float type conversion and take n decimal places

sponsored links
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.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of JS float type conversion and take n decimal places

  • the basis of css + div

    css syntax features: 1. In the introduction of style sheets documents <style> tag to use, and on <head> 2. Syntax: stylesheet ( [Attribute: attribute value]; [attribute: attribute value]; ) For example, <style type="text/css" ...

  • DWR practice papers AJAX

    DWR (Direct Web Remoting) is a WEB framework for long-distance calls. Take advantage of this framework can become very easy to develop AJAX. DWR can use client-side JavaScript directly call the service using the Java client value back to the Ways and Java

  • Javascript variables not defined in the judge (undefine) the problem

    Originally, the variable is not defined very easy to judge, can be used directly on the typeof Today, however, used in the project dynamic variables (eval (variable)), resulting in the following code is invalid Finally only way to determine the use o ...

  • hibernate study of the thirteenth chapter

    load method and principle analysis of lazy loading The purpose of lazy loading, to reduce unnecessary database queries and enhance performance. Mapping components to use in front of the user category, the Writing test code to do to change: public class Ma

  • A classic english Rails AJAX sorting and paging sample

    This is a classic (in my opinion ^ _ ^) is used to display, ajax call to sort, search and paging example. This sample is characterized by the process of writing put considerable wordily, designed to kill Mother. So very good understanding, very primary, v

  • Topsy Ruby Series: Topsy Symbol

    Learn Ruby would Symbol it puzzled me too, so look to spend more time Symbol. Symbol Chinese name symbols, because the tags are used to a certain kind of things. Early read some information, in my mind, feel like a String, like Symbol, you can visit ...

  • From Java to Ruby

    Java is a mature, tested, and are quick (), or wordy. From Java to the Ruby, could be expected to reduce the code size, but also could be expected to spend less time to put together a quick prototype. Similarities: And Java, in Ruby, the ... Garbage ...

  • Java, JDBC and MySQL Types - MySql databases

    MySQL Connector / J in the deal with MySQL data types and Java data type conversion processing is very flexible. Although there may be rounding, overflow or loss of accuracy, when in normal circumstances, can any MySQL data type is converted to java.lang.

  • JS in the Date type conversion


  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries