{"id":177,"date":"2011-04-12T13:09:41","date_gmt":"2011-04-12T13:09:41","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=177"},"modified":"2011-04-12T13:09:41","modified_gmt":"2011-04-12T13:09:41","slug":"fractions-numeric-input","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/fractions-numeric-input\/","title":{"rendered":"Accept fractions in place of numeric input"},"content":{"rendered":"<p>If there&#39;s one thing your competitor probably isn&#39;t doing, when it comes to online tools, it&#39;s accepting fractions for numeric input.<\/p>\n<p>For instance, if you have a tool that calculates the square footage of a room, why not allow the user to enter:<\/p>\n<p>Width:&nbsp; 5 3\/4<br \/>\n\tLength: -2 3\/8<\/p>\n<p>Using ColdFusion for our example, by running your fields through a loop and detecting the presence of a &quot;\/&quot; in the input, we can convert the value to a decimal number for use in our processing script:<\/p>\n<p><code>&lt;cfloop collection=&quot;#url#&quot; item=&quot;key&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfif Find(&quot;\/&quot;, url[key])&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset url[key] = trim(url[key])&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset frac = ListLast(url[key], &quot; &quot;)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfif frac eq url[key]&gt;&lt;cfset url[key] = 0&gt;&lt;\/cfif&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfif Left(url[key], 1) neq &quot;-&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset url[key] = Val(url[key]) + Evaluate(frac)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfelse&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset url[key] = Val(url[key]) - Evaluate(frac)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;\/cfif&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/cfif&gt;<br \/>\n\t&lt;\/cfloop&gt;<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If there&#39;s one thing your competitor probably isn&#39;t doing, when it comes to online tools, it&#39;s accepting fractions for numeric input. For instance, if you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[15,34],"tags":[82],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=177"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/177\/revisions\/178"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}