<p>I recently went through a bit of a journey to find a solution for converting decimal values to useable fractions up to 1/32 precision. To be clear I wanted measurable fractions like 1/32, 1/8, 3/4, etc, but the decimal data I was feeding in was not precise enough for an exact conversion. I am posting my solution here to hopefully save someone else the trouble, as this community has helped me solve many other questions I've had in the past.</p>
<p> </p>
<p>I wrote my own JavaScript function that will convert a string like <strong>032.437</strong> to <strong>32 - 7/16</strong> by finding the closest relevant fraction and adding it as a suffix to the whole number. </p>
<p>When calling the function, you include the column name of the data you are converting and then the index after the decimal place. For data like 032.437 you would call it like thus:</p>
<p> </p>
<p><strong>fraction(columnName, 4)</strong></p>
<p> </p>
<p>I apologize I have not included a sample report.</p>
<p> </p>
<p>Just to be clear, this function is only precise to 1/32. The code is not complex so it would be easy to modify if you need to go to 1/64 precision. It's mostly a bunch of if - then lines.</p>
<p> </p>
<p> </p>
<p> </p>
<p>Use this post if (like me) you want to know how to add your own javascript functions you can call when creating a computed column to your dataset:</p>
<p> <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/22052-reuse-javascript-how-to-put-in-library/'>http://developer.actuate.com/community/forum/index.php?/topic/22052-reuse-javascript-how-to-put-in-library/</a></p>
<p> </p>
<p> </p>
<p> </p>
<p>I hope this proves useful to someone</p>
<pre class="_prettyXprint _lang-js">
function fraction(column, index){
var text = column;
var whole= text.substring(0, index-1);
var fraction = 0;
var part= parseInt(text.substring(index))
if((part > 016) && (part < 047)){
fraction = " -1/32"}
else if((part > 046) && (part < 078)){
fraction = " -1/16"}
else if((part > 077) && (part < 109)){
fraction = " -3/32"}
else if((part > 108) && (part < 141)){
fraction = " -1/8"}
else if((part > 140) && (part < 172)){
fraction = " -5/32"}
else if((part > 171) && (part < 203)){
fraction = " -3/16"}
else if((part > 202) && (part < 234)){
fraction = " -7/32"}
else if((part > 233) && (part < 266)){
fraction = " -1/4"}
else if((part > 265) && (part < 296)){
fraction = " -9/32"}
else if((part > 295) && (part < 328)){
fraction = " -5/16"}
else if((part > 327) && (part < 359)){
fraction = " -11/32"}
else if((part > 358) && (part < 392)){
fraction = " -3/8"}
else if((part > 391) && (part < 423)){
fraction = " -13/32"}
else if((part > 422) && (part < 453)){
fraction = " -7/16"}
else if((part > 452) && (part < 484)){
fraction = " -15/32"}
else if((part > 483) && (part < 516)){
fraction = " -1/2"}
else if((part > 515) && (part < 457)){
fraction = " -17/32"}
else if((part > 546) && (part < 579)){
fraction = " -9/16"}
else if((part > 578) && (part < 610)){
fraction = " -19/32"}
else if((part > 609) && (part < 641)){
fraction = " -5/8"}
else if((part > 640) && (part < 673)){
fraction = " -21/32"}
else if((part > 672) && (part < 703)){
fraction = " -11/16"}
else if((part > 702) && (part < 735)){
fraction = " -23/32"}
else if((part > 734) && (part < 766)){
fraction = " -3/4"}
else if((part > 765) && (part < 798)){
fraction = " -25/32"}
else if((part > 797) && (part < 829)){
fraction = " -13/16"}
else if((part > 828) && (part < 860)){
fraction = " -27/32"}
else if((part > 859) && (part < 892)){
fraction = " -7/8"}
else if((part > 891) && (part < 923)){
fraction = " -29/32"}
else if((part > 922) && (part < 954)){
fraction = " -15/16"}
else if((part > 953) && (part < 984)){
fraction = " -31/32"}
else{
fraction = ""}
return (whole + fraction).replace(/^0+/, '')
} </pre>