Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve docs for faker.number.float #2607

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/modules/number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,14 @@ export class NumberModule extends SimpleModuleBase {
}

/**
* Returns a single random floating-point number.
* The lower bound is inclusive, the upper bound is exclusive, unless `multipleOf` is passed.
* Returns a single random floating-point number, by default between `0.0` and `1.0`. To change the range, pass a `min` and `max` value. To limit the number of decimal places, pass a `multipleOf` or `fractionDigits` parameter.
*
* @param options Upper bound or options object.
* @param options.min Lower bound for generated number. Defaults to `0.0`.
* @param options.max Upper bound for generated number. Defaults to `1.0`.
* @param options.precision Precision of the generated number, for example `0.01` will round to 2 decimal points.
* If precision is passed, the upper bound is inclusive.
* @param options.multipleOf The generated number will be a multiple of this property.
* This property can be used to limit the result to a specific number of decimal digits.
* For example `0.01` will round to 2 decimal points.
* If `multipleOf` is passed, the upper bound is inclusive.
* This option is incompatible with the `fractionDigits` option.
* @param options.fractionDigits The maximum number of digits to appear after the decimal point.
* This option is incompatible with the `multipleOf` option.
* @param options.min Lower bound for generated number, inclusive. Defaults to `0.0`.
* @param options.max Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`.
* @param options.precision Deprecated alias for `multipleOf`. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
* @param options.multipleOf The generated number will be a multiple of this parameter. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
* @param options.fractionDigits The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
*
* @throws When `min` is greater than `max`.
* @throws When `precision` is negative.
Expand All @@ -111,12 +104,13 @@ export class NumberModule extends SimpleModuleBase {
* @example
* faker.number.float() // 0.5688541042618454
* faker.number.float(3) // 2.367973240558058
* faker.number.float({ min: -1000000 }) //-780678.849672846
* faker.number.float({ max: 100 }) // 17.3687307164073
* faker.number.float({ multipleOf: 0.25 }) // 3.75
* faker.number.float({ min: 20, max: 30 }) // 23.94764115102589
* faker.number.float({ multipleOf: 0.25, min: 0, max:10 }) // 7.75
* faker.number.float({ fractionDigits: 1 }) // 0.9
* faker.number.float({ min: 10, max: 100, multipleOf: 0.02 }) // 35.42
* faker.number.float({ min: 10, max: 100, fractionDigits: 3 }) // 65.716
* faker.number.float({ min: 10, max: 100, multipleOf: 0.001 }) // 65.716 - same as above
*
* @since 8.0.0
*/
Expand All @@ -125,30 +119,29 @@ export class NumberModule extends SimpleModuleBase {
| number
| {
/**
* Lower bound for generated number.
* Lower bound for generated number, inclusive.
*
* @default 0.0
*/
min?: number;
/**
* Upper bound for generated number.
* Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed.
*
* @default 1.0
*/
max?: number;
/**
* The number of digits to appear after the decimal point.
* The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
*/
fractionDigits?: number;
/*
* Precision of the generated number.
* Deprecated alias for `multipleOf`. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
*
* @deprecated Use `multipleOf` instead.
*/
precision?: number;
/**
* The generated number will be a multiple of this property.
* If multipleOf is passed, the upper bound is inclusive.
* The generated number will be a multiple of this parameter. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
*/
multipleOf?: number;
} = {}
Expand Down