:number
type description >= 1.0.0
:number
type is another one of the most basic built-in types. It supports the following data attributes:
[min,max]
the size range is used to set the minimum and maximum values of the number.
// Set a number ranging from 1 to 100
Such.as(":number:[1,100]");
// Numbers theoretically contain the maximum and minimum values by default
// Because of the random value floating point number, the probability of the maximum and minimum values is very small
// If you really do not want to include the maximum or minimum value, you can add the configuration attribute `exclude`
// Configured as 'min' to not include the minimum value, and configured as 'max' to not include the maximum value
// Configured as 'min,max' or 'both' as the minimum and maximum values are both not included
Such.as(":number:[1,100]:#[exclude='max']");
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
%
formatting, when the number type is not formatted, the decimal part is likeMath.random()
, but usually this is not the data we want. Under normal circumstances, we will format it, suchjs uses a separate extraction librarynprintf
to format numbers similar to c language.
Such.as(":number:[1,100]:%.2f");
// The output is similar to: `32.58`
1
2
2