Nodejs String to Float Convert toFloat()

Here you can find the source of toFloat()

Method Source Code

/*//from   ww w.java2s  .c  om
 * String.toFloat.js
 * 
 * Copyright (c) 2012 Tomasz Jakub Rup <tomasz.rup@gmail.com>
 *
 * https://github.com/tomi77/Date.toLocaleFormat/
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/**
 * Return a float representation of string.
 * 
 * @return float
 */
String.prototype.toFloat = function() {
   return parseFloat(this);
}

Related

  1. tryParseToFixed(decimalPlaces)
    Number.prototype.tryParseToFixed = function(decimalPlaces) {
      if(!decimalPlaces) decimalPlaces = 0;
      if (isNaN(this)) {
        throw this + ' could not be converted to a Number.';
      return parseFloat(this).toFixed(decimalPlaces);
    
  2. toFloat()
    String.prototype.toFloat = function(){
      return parseFloat(this);
    };
    
  3. toFloat()
    String.prototype.toFloat = function(){
        return parseFloat(this);
    function angle(cx, cy, ex, ey) {
      var dy = ey - cy;
      var dx = ex - cx;
      var theta = Math.atan2(dy, dx); 
      theta *= 180 / Math.PI; 
      return theta;
    ...
    
  4. toFloat()
    String.prototype.toFloat = function()
      var regexFloat = /[^0-9\.]+/g;
      this.number = this;
      this.number = this.number.replace( regexFloat, '' );
      this.number = ( Math.round( this.number * 100) / 100).toFixed(2);  
      return this.number;  
    
  5. toFloat(alt)
    String.prototype.toFloat  = Number.prototype.toFloat  = jCube.String.toFloat  = function ( alt) {
      return parseFloat(this).check( alt||0);
    jCube.Include("Number.check");