Here I am pasting the code that I modified from macromedia website to make a slider. Everything looks like fine but the number … 0.090 is displayed like 0.90 , I am so stressed not to understand why it does that. Here is the code-
//-----------------Initial Setup----------------------//
//text label from the component definition goes to the text instance.text. Instances has "_" in variable.
txt_label.text = txtLabel;
//-----------------onEnterFrame---------------------//
//convert the sliderknob x position to the value required
this.onEnterFrame = function() {
var valueText:Number = (slider_knob._x/(g_line._width/maxNumber));
//onEnterFrame run the function format()
txt_value.text = format(valueText);
//trace(Math.floor(1.111));
};
//------------------decimal formatter------------------//
//Formatter from Macromedia website search "decimal value"
function format(value:Number) {
// get the value
//var value:Number = valueText;
// format the number to numPrecision decimal points
var formattedValue:String = formatPrecision(value, numPrecision);
// return the formatted value
return formattedValue;
}
function formatPrecision(num:Number, precision:Number, splitCharacter:String):String {
// formats a number to given precision
// thanks to bokel for the original algorithm on which this method is based
var precision:Number = (precision=Math.abs(precision));
if (precision == 0) {
// no decimal points
var returnValue = String(Math.round(num));
return returnValue;
}
if (splitCharacter == null) {
// setup default split character
splitCharacter = ".";
}
// calculate precision
var returnValue:String = String(Math.floor(num)+splitCharacter+Math.floor(num*Math.pow(10, precision)).toString().substr(-precision));
return returnValue;
}
…I have included my fla File. Please help me find the bug. I look forward hearing from someone.
Sincerely,
Rabi