Using decimal values

As part of the PHP project, I need to return the sine value of each value included in an arbitrary interval. Moreover, I also need to be able to set the "area" of the function, that is, how many decimal places I need cyclically.

For example: 1 decimal place for an interval from 1 to 3 inclusive: 1, 1.1, 1.2, ... 2.8, 2.9, 3

2 decimal places for the same interval

1, 1.01, 1.02 ... 2.98, 2.99, 3

Etc ... I tried to do this with the for loop, but it would only consider natural numbers.

Suggestions?

0
source share
1 answer

You can customize the code under the code according to your needs:

$start = 1; $end = 3; $place = 1; $step = 1 / pow(10, $place); for($i = $start; $i <= $end; $i = round($i + $step, $place)) { echo $i . "\n"; } 

Output:

 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 
+3
source

Source: https://habr.com/ru/post/1258544/


All Articles