How to convert string to number format and round it the value.
Hello everyone, I have a problem how to convert string to number or money format. I'm already used method number_format and money_format from php but it still not work. The callback of error's the value must be a float. So what must I do for this?
So for example :
$total_price = "134.400"
// After convert it, the result must be like this
$total_price = 134.400
I'm not sure I understand your question. If it's a matter of having the number stored as text ($number = '21'), the only thing you need to do is add (int) or (float) before the variable to cast it as such:
@cg0012 how about make / convert string to type data int for manage calculation Because if I'm using a float or int, it's will be redirect a int without decimal or value zero.
So I want to be like this :
$total_price = "134.400"
// After convert it the result is like this.
$total_price = 134.400
@adnanerlansyah403 start dumping your variables at each step until you find where its failing.
$cartTotal = Cart::total(); // For example, this value is : "100000"
dd($cartTotal);
//rest of code
}
//if that looks good then ->
$cartTotal = Cart::total(); // For example, this value is : "100000"
dd($coupon_amount);
//rest of code
}
//next try
$cartTotal = Cart::total(); // For example, this value is : "100000"
if($coupon_amount == 0 || $coupon_amount == null) {
return response()->json([
'message' => 'Coupon amount has run out!',
]);
}
dd($coupon_minimum_order_amount);
}
//you could also debug by using if statements
if(is_numeric($coupon_check->coupon_percent_off)) {
dd("percent off is numeric")
}
else {
dd('hey the percent off is jacked up");
}
@adnanerlansyah403 number_format was already mentioned above my suggestion would be to go to the the php manual and read up on it, it's pretty powerful.