actionscript 3 - Why are my numeric stepper values so far out past the decimal point? -


i'm using flex 4.6 spark numeric stepper in app , when enter .9 returns, "0.9000000953674316". can enter value actually. doing of them.

if use arrow buttons moves 0 1 sets value "0.09999990463256836".

update:
running more tests. if start , 0 , go down it's:

0
-0.1
-0.2
-0.30000000000000004
-0.4

and if go it's:

-0.30000000000000004
-0.20000000000000004
-0.10000000000000003
-2.7755575615628914e-17
nan

here formatter code:

precision = 100; public function formatnumericstepper(value:number):string {     return string(int(value*precision)/precision); } 

note: value gets stuck @ -.7 or .28. works fine whole numbers it's buggy heck numbers less one. or i'm doing wrong.

with finessing , helpful direction @dodgerthud following seems working:

mxml:

<s:numericstepper id="numericstepper" snapinterval="0" stepsize=".01"                   valueformatfunction="formatnumericstepper"                   valueparsefunction="valueparsefunctionnew"/> 

actionscript:

public var precision:int = 100;  public var fixedposition:int = 2;  /**  * format numeric stepper  * trim down 2 decimal places.  * */ public function formatnumericstepper(value:number):string {     var out:string;     if (fixedposition!=0) {         out = number(value.tofixed(fixedposition)).tostring();     }     else {         out = string(int(value * precision) / precision);     }     return out; }   public function valueparsefunction(value:string):number {     var out:number;     if (fixedposition!=0) {         out = number(number(value).tofixed(fixedposition));     }     else {         out = number(value);     }     return out; } 

i think getting stuck because if have small enough step size, .1 , rounding using value*100/100 rounding down. therefore, never large or small enough step past value.

the else statements removed. kept them in if it's possible dynamically can use step size decimal position counter.

so if step size .1 fixedposition 1. if step size .01 fixedposition 2. if .001 or .999 fixed position 3.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -