Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle the decimal values of my dropdown list without rounding or trimming zeros
    primarykey
    data
    text
    <p>I have a drop down list with decimal values. (formatted as string)</p> <pre><code>&lt;select id="SizeBox"&gt; &lt;option id="size_5" value="14.00"&gt;14&lt;/option&gt; &lt;option id="size_6" value="16.00"&gt;16&lt;/option&gt; &lt;option id="size_7" value="18.00"&gt;18&lt;/option&gt; &lt;option id="size_8" value="20.00"&gt;20&lt;/option&gt; &lt;option id="size_9" value="24.00"&gt;24&lt;/option&gt; &lt;option id="size_10" value="28.00"&gt;28&lt;/option&gt; &lt;option id="size_11" selected="selected" value="28.35"&gt;28,35&lt;/option&gt; &lt;option id="size_12" value="36.00"&gt;36&lt;/option&gt; &lt;/select&gt; </code></pre> <p>I always take the selected value and save it in a variable:</p> <pre><code>var backupSize = "28.35"; </code></pre> <p>When the user selected another size and wants to undo his changes, I provide a reset button that should select the backupSize value again.</p> <pre><code>SelectSize(parseFloat(backupSize).toFixed(2)); function SelectSize(size) { $('#SizeBox').val(size); } </code></pre> <p>The problem is that using this toFixed method removes my decimal precision and pass the value 28.00 to the SelectSize function. Offcourse, there is no option in my list with this value so the reset function fails.</p> <p>If i use the SelectSize function without the toFixed(2) part, then values like "20.00" will be passed as "20" and the SelectSize function will also fail to reset the size in the dropdown box.</p> <p>I've searched for function that handle these decimal numbers just like strings but without success so far. How can i solve this?</p> <p>Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload