phpjs
Version:
56 lines (46 loc) • 1.81 kB
Markdown
layout: page
title: "JavaScript doubleval function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/doubleval:389
- /functions/view/doubleval
- /functions/view/389
- /functions/doubleval:389
- /functions/389
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's doubleval
{% codeblock var/doubleval.js lang:js https://raw.github.com/kvz/phpjs/master/functions/var/doubleval.js raw on github %}
function doubleval (mixed_var) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// - depends on: floatval
// % note 1: 1.0 is simplified to 1 before it can be accessed by the function, this makes
// % note 1: it different from the PHP implementation. We can't fix this unfortunately.
// * example 1: doubleval(186);
// * returns 1: 186.00
return this.floatval(mixed_var);
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/var/doubleval.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/var/doubleval.js)
### Example 1
This code
{% codeblock lang:js example %}
doubleval(186);
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
186.00
{% endcodeblock %}
### Other PHP functions in the var extension
{% render_partial _includes/custom/var.html %}