Search code examples
javajavascriptdojofractions

work with fractions - Java NumberFormat pattern


I am using dojo, and i read this framework uses the Java NumberFormat pattern.

My question is:how to maintain the values of slider with fractions, and not the division. For example, 1/3 and not 0.333333333. This is because, in future i need to invert 1/3 to 3/1.

So the issue is, how maintain the value in fraction.

var theSlider = new dijit.form.HorizontalSlider({
                value:5,
                onChange: function(){
                    console.log(arguments);
                },
                name:"input"+[i],
                slideDuration:0,
                onChange:function(val){ dojo.byId('value'+[i]).value = dojo.number.format(1/val,{places:4})},
                minimum:1,
                maximum:9,
                discreteValues:9,
                style:{width:"400px"}
            },node);

Solution

  • simply:

    onChange:function(val){ dojo.byId('value'+[i]).value = "1/" + val;},
    

    Solved, thanks