如何使用php将字符串数字转换为整数

如何使用php将字符串数字转换为整数,php,Php,当我在PhpMyAdmin it result 5.0中转换轮数(4.9813200498132,1)时,我遇到了一个问题,为什么会发生这种情况?然后,当我尝试仅在php it result 5中转换值时。如何将结果5.0应用到php端。?是否需要将字符串数字转换为整数?为了更好地理解,我将向大家分享我创建的示例方程 php中的公式: $first_wtd_item_first_option = str_replace( ',', '', $high_item_d_wtd_data->t

当我在PhpMyAdmin it result 5.0中转换轮数(4.9813200498132,1)时,我遇到了一个问题,为什么会发生这种情况?然后,当我尝试仅在php it result 5中转换值时。如何将结果5.0应用到php端。?是否需要将字符串数字转换为整数?为了更好地理解,我将向大家分享我创建的示例方程

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).'%');
输出:

$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).'%');


谢谢。

你应该用10的倍数,而不是100的倍数,你也可以用

结果:

$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).'%');

5.0%

你应该用10的倍数,而不是100的倍数,你也可以用

结果:

$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).'%');
5.0%

您可以使用

你可以用


我猜@Morgan你不明白我的问题。我的意思是。为什么产出是5%,有可能把5%提高到5.0%吗?我猜@Morgan你不明白我的问题。我的意思是。为什么产量是5%,有可能把5%提高到5.0%吗?这能回答你的问题吗?这回答了你的问题吗?