Although the value on a slider component is always an integer we can easily use it to select decimal numbers. In the example below we want find the sales tax on a purchase of any amount up to $100.00
We do this by making the maximum on the slider 100 times the maximum amount we want to select. When we show the value, we divide the value on the slider by 100 to get dollars and cents.
sldCost.addEventListener(MouseEvent.MOUSE_MOVE,showCost);
function showCost(e:MouseEvent): void {
var cost:Number=sldCost.value/100;
var tax:Number=cost*0.06; //6% tax
lblCost.text="$" + cost.toFixed(2);
lblTax.text="$" + tax.toFixed(2);
} //showCost
Notice that we use the toFixed function of a number to force it to display two decimal places. Without this function, $2.70 would display as $2.7.
To Do: Add the total of the cost and tax to the display. We have used 6% sales tax. Adjust it for your state, or use a slider to let the user select the amount of sales tax. Download the flash file