Lodash _.isFloat() 方法
Lodash _.isFloat() 方法检查给定值是否为浮点值并返回相应的布尔值。
句法:
_.isFloat( value );
参数:此方法接受上面提到的单个参数,如下所述:
- value:要检查浮点值的给定值。
返回值:此方法返回一个布尔值(如果给定值是偶数则返回真,否则返回假)。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking
console.log("The Value is Float : " + _.isFloat(5.56));
console.log("The Value is Float : " + _.isFloat(5.0));
console.log("The Value is Float : " + _.isFloat(5));
console.log("The Value is Float : " + _.isFloat(0.5));
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking
console.log("The Value is Float : " + _.isFloat(10));
console.log("The Value is Float : " + _.isFloat());
console.log("The Value is Float : " + _.isFloat(23.60));
console.log("The Value is Float : " + _.isFloat(50.08));
输出:
The Value is Float : true
The Value is Float : false
The Value is Float : false
The Value is Float : true
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking
console.log("The Value is Float : " + _.isFloat(10));
console.log("The Value is Float : " + _.isFloat());
console.log("The Value is Float : " + _.isFloat(23.60));
console.log("The Value is Float : " + _.isFloat(50.08));
输出:
The Value is Float : false
The Value is Float : false
The Value is Float : true
The Value is Float : true