randomFloat() does not always return a float
localheinz opened this issue · 1 comments
localheinz commented
Summary
When using $faker->randomFloat()
, sometimes an int
is returned.
Versions
Version | |
---|---|
PHP | any |
fzaninotto/faker |
1.9.2 |
Self-enclosed code snippet for reproduction
$faker = Faker\Factory::create();
$value = $faker->randomFloat();
assert(is_float($value));
Expected output
No issues in all cases.
Actual output
Fails randomly.
💡 This can likely be solved by using appropriate return type declarations in next
or casting the value to a float
before returning it.
villfa commented
@localheinz are you sure the problem you had came from randomFloat()
?
The git history shows that this function always directly returns the result of round()
, and round()
can only return a float: https://3v4l.org/Y0Oi3
I've also tried to reproduce the problem with the script below but I only got floats:
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
do {
$value = $faker->randomFloat();
} while (is_float($value));
var_dump($value);