I am trying to print a value here, I am getting a value with four zeros .0000 125.000, I want to remove it and display just 125
@if(empty($product->qty_available))
Availble Qty (Null)
@else
Availble Qty ({{$product->qty_available}})
@endif
I am trying to print a value here, I am getting a value with four zeros .0000 125.000, I want to remove it and display just 125
@if(empty($product->qty_available))
Availble Qty (Null)
@else
Availble Qty ({{$product->qty_available}})
@endif
You can go for a ceil
value of the float. If it equals the integer part of the float before the decimal, we print the integer form of it, else go for the float as is.
@if(empty($product->qty_available))
Availble Qty (Null)
@else
Availble Qty ({{ ceil($product->qty_available) == (int)$product->qty_available ? (int)$product->qty_available : $product->qty_available}})
@endif
If you are working with quantity there is no reason to use float, you should use int instead. But if you have to and you want no decimals you should try this:
@if(empty($product->qty_available))
Availble Qty: (Null)
@else
$product->qty_available = rtrim(rtrim($product->qty_available, "0"),".")
Availble Qty: ({{$product->qty_available}})
@endif
This solution will remove both the (.) and the sequence of zeros of your string