0

I got problem why is it happen when I convert the number of ROUND(4.9813200498132,1) in PhpMyAdmin it result 5.0 then when i try to convert the value in php it result 5 only. how to make the result 5.0 to the php side.? is it need to convert the string number to int number? to understand well i will share to you guys the sample equation that i create.

Equation in php:

$first_wtd_item_first_option = str_replace( ',', '', $high_item_d_wtd_data->total_qty ); $first_wtd_item_second_option = str_replace( ',', '', $high_item_a_wtd_data->total_qty ); $first_wtd_item_third_option = str_replace( ',', '', $high_item_b_wtd_data->total_qty ); $first_wtd_item_computation1 = $first_wtd_item_second_option + $first_wtd_item_third_option; $first_wtd_item_computation2 = ($first_wtd_item_first_option / $first_wtd_item_computation1); $first_wtd_item_computation3 = $first_wtd_item_computation2 * 100; $first_wtd_item_final_result = (round($first_wtd_item_computation3,1).'%'); 

Output:

rounded

Thank you.

1

2 Answers 2

1

You should multiple with 10, not with 100, also you can use number_format()

$first_wtd_item_first_option = str_replace( ',', '', $number); $first_wtd_item_second_option = str_replace( ',', '', $number); $first_wtd_item_third_option = str_replace( ',', '', $number); $first_wtd_item_computation1 = $first_wtd_item_second_option + $first_wtd_item_third_option; $first_wtd_item_computation2 = ($first_wtd_item_first_option / $first_wtd_item_computation1); $first_wtd_item_computation3 = number_format((float) $first_wtd_item_computation2 * 10, 1, '.', ''); $first_wtd_item_final_result = $first_wtd_item_computation3.'%'; 

Result:

5.0%

Sign up to request clarification or add additional context in comments.

1 Comment

I guess @Morgan you didn't understand my question. what i mean for that. why the output is 5%, is it possible to make the 5% to 5.0%?
1

you can use number_format

$first_wtd_item_final_result = (number_format(round($first_wtd_item_computation3,1), 1).'%'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.