---
title: "3 < 3 = true"
type: "forum-thread"
url: "https://www.webforum.nu/amne/flash/164982-3-3-true"
topic: "Flash"
topic_url: "https://www.webforum.nu/amne/flash"
author: "Blixtsystems"
published: "2007-09-28T11:57:24.000Z"
updated: "2007-09-28T17:46:09.000Z"
replies: 2
views: 387
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/flash/164982-3-3-true"
---

# 3 < 3 = true

## #1 — Blixtsystems, 2007-09-28T11:57Z

Denna kod:

```
var l:Number=pile[i].num;
trace("num:"+l);
var j:Number=0;
for(j=0;j<l;j++){
	trace("push:"+pile[i].value+", j:"+j+", l:"+l+", j &lt; l:"+(j<l));
	trace("typeof j:"+typeof(j)+", typeof l:"+typeof(l));
}
```

ger denna output:

```
num:3
push:0.05, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:2, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, [b][3][red]j:3, l:3, j < l:true[/red][/3][/b]
typeof j:number, typeof l:number
```

Testar jag istället med att köra:

```
var l:Number=3;
trace("num:"+l);
var j:Number=0;
for(j=0;j<l;j++){
	trace("push:"+pile[i].value+", j:"+j+", l:"+l+", j &lt; l:"+(j<l));
	trace("typeof j:"+typeof(j)+", typeof l:"+typeof(l));
}
```

Så får jag:

```
num:3
push:5, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:5, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:5, j:2, l:3, j < l:true
typeof j:number, typeof l:number
```

Alltså...värdet av "pile.num" är av typen nummer med värdet 3, men ändå så anser Flash att det är mindre än 3.
Ändrar jag så jag hårdkodar det till 3 så anser Flash att det inte är mindre än 3.
"l" och "j" är varibler deklarerade lokalt i en funktion.

Detta händer inte vanligtvis utan vanligtvis fungerar det som väntat...exempel på hur det ser ut då jag kör hela funktionen med lite olika värden:

```
num:3
push:0.01, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.01, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.01, j:2, l:3, j < l:true
typeof j:number, typeof l:number

num:3
push:0.05, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:2, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:3, l:3, j < l:true
typeof j:number, typeof l:number

num:1
push:0.5, j:0, l:1, j < l:true
typeof j:number, typeof l:number

num:2
push:1, j:0, l:2, j < l:true
typeof j:number, typeof l:number
push:1, j:1, l:2, j < l:true
typeof j:number, typeof l:number

num:1
push:5, j:0, l:1, j < l:true
typeof j:number, typeof l:number

num:2
push:100, j:0, l:2, j < l:true
typeof j:number, typeof l:number
push:100, j:1, l:2, j < l:true
typeof j:number, typeof l:number

num:3
push:1000, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:1000, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:1000, j:2, l:3, j < l:true
typeof j:number, typeof l:number
```

 :q 

Om någon har en idé om hur detta är möjligt vorde det kanon, men jag är mest ute efter medlidande  :(

Permalänk: https://www.webforum.nu/p/164982

## #2 — emission, 2007-09-28T16:09Z

Hmmm..skumt..måhända kan det vara ett internt precisionsproblem, beroende på att Number-typen är så allomspännande (fungerar ju som flyttal också..). I AS3.0 kan man använda typen int i stället.

var l:Number=Number("" + pile*.num);*

Permalänk: https://www.webforum.nu/p/2035210

## #3 — Blixtsystems, 2007-09-28T17:46Z

Det verkar som du har rätt.
Jag häll på och mixtrade lite och det funkar att omvandla värdet till en sträng och tillbaka eller att köra Math.round

Permalänk: https://www.webforum.nu/p/2035228

---

Tråden på webben: https://www.webforum.nu/amne/flash/164982-3-3-true
