php-fakerHow can I generate decimal numbers using PHP Faker?
To generate decimal numbers using PHP Faker, you can use the randomFloat()
method. This method takes two parameters, the first being the minimum value and the second being the maximum value. The generated number will be a float between the two parameters. For example:
<?php
$faker = Faker\Factory::create();
echo $faker->randomFloat(2, 0, 10);
// Output: 8.25
The randomFloat()
method takes two parameters:
$nbMaxDecimals
: The maximum number of decimals that will be generated.$min
: The minimum value for the generated number.$max
: The maximum value for the generated number.
For example, to generate a float between 0 and 10 with a maximum of 2 decimals, you would use the following code:
<?php
$faker = Faker\Factory::create();
echo $faker->randomFloat(2, 0, 10);
// Output: 8.25
For more information on the randomFloat()
method, please refer to the PHP Faker documentation.
More of Php Faker
- How can I generate a fake timestamp using PHP Faker?
- How do I use the Laravel Faker numerify function?
- How do I generate JSON data using PHP Faker?
- How do I generate a zip file using PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How do I generate a valid VAT number using Laravel Faker?
- How can I generate a zip code using Laravel Faker?
- How can I generate fake data in XLSX format using PHP Faker?
- How do I check which version of Laravel Faker I am using?
- How do I use PHP Faker to generate XML data?
See more codes...