Rails Spree - Round the product value to 2 decimal cases on a item_form.number_field

188 Views Asked by At

my problem is that on spree on the order page where the input stock number is, this lines of codes:

<td class="cart-item-quantity" data-hook="cart_item_quantity">
  Stock.
  <%= item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %>
</td>

Will produce the following html:

<td class="cart-item-quantity" data-hook="cart_item_quantity">
Stock.
<input id="quantity_dcm_cart" class="line_item_quantity_dcm"type="number" value="0.7000000000000001" step="0.1" size="5" name="quantity_dcm_cart" min="0">
<input id="order_line_items_attributes_0_quantity" class="line_item_quantity" type="number" hidden="hidden" value="7" size="5" name="order[line_items_attributes][0][quantity]" min="0">
</td>

The problem is that value is 0.700000001 and i wanted to have only one decimal cases and be round to 0.7 as the value of that input or the the browser will say the value is not accepted.

Any way that using this spree rails code to achieve this?

Thanks.

P.S.: Зелёный did a jsfiddle right now where you can easily see what's the problem. Thanks. https://jsfiddle.net/m2mLg9sr/

0

There are 0 best solutions below