# Help with Math.Round

**URL:** <https://forum.kirupa.com/t/help-with-math-round/25652>\
**Category:** flash\
**Created:** [July 15, 2003, 1:08pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652 "2003-07-15T13:08:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wyclef](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@wyclef](https://forum.kirupa.com/u/wyclef)\
**Post date:** [July 15, 2003, 1:08pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/1 "2003-07-15T13:08:50Z")

</div>

Hello :elderly:

I’m running into some problems with math.round not working how I’d like it to work. I’m using a pixel font, and if the text does not land on a whole pixel, it becomes blurry. I suspect it might be an easy fixed to the trained eye so I’ve posted the script. Thanks! 😉  
[AS]  
function setDragMask() {

```
ts.dragger.onPress = function() {
	this.released = false;
	startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
	// The scrolling animation
	ts.theText.onEnterFrame = function() {
		trace("enterframe");
		
		scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);
		
		ts.dragger._height = 30;
		// Set a new target y position
		targY = -ts.dragger._y*scrollAmount;
		
		Math.round()(this._y -= Math.round((this._y-targY)/5));
		this._y -= (this._y-targY)/5;
		trace(Math.abs(this._y)+' = '+Math.abs(targY));
		trace(Math.abs(this._y)+'&lt;='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'&gt;='+Math.abs(targY-1));
		if ( (Math.abs(this._y)&lt;=Math.abs(targY)+1)&&(Math.abs(this._y)&gt;=Math.abs(targY)-1)) {
			trace('inside');
			if(ts.dragger.released == true) {
				trace('delete');
				delete this.onEnterFrame;
			}
		}
	}
}

```

[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 1:25pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/2 "2003-07-15T13:25:21Z")

</div>

```auto
this._y -= Math.round((this._y-targY)/5);
this._y = Math.round(this._y)

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 1:26pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/3 "2003-07-15T13:26:07Z")

</div>

```auto
Math.round()(this._y -= Math.round((this._y-targY)/5));

```

doesn’t mean anything. It should be

```auto
Math.round( whatYouWantToround ) ;

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 1:33pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/4 "2003-07-15T13:33:39Z")

</div>

Does this look better? I tried it and it seems to work, but the scrolling isn’t as smooth any more. I’m wondering if that’s just the compromise for forcing it on a whole pixel?

[AS]  
// --------------------------------------------------------------------------------------  
function setDragMask() {

```
ts.dragger.onPress = function() {
	this.released = false;
	startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
	// The scrolling animation
	ts.theText.onEnterFrame = function() {
		trace("enterframe");
	
		scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);
		// Adjust the height of the dragger to reflect the amount of content available to see
		ts.dragger._height = 30;
		// Set a new target y position
		targY = -ts.dragger._y*scrollAmount;
		
		Math.round(this._y -= Math.round((this._y-targY)/5));
		this._y -= Math.round((this._y-targY)/5);

```

this.\_y = Math.round(this.\_y)

```
		trace(Math.abs(this._y)+' = '+Math.abs(targY));
		trace(Math.abs(this._y)+'&lt;='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'&gt;='+Math.abs(targY-1));
		if ( (Math.abs(this._y)&lt;=Math.abs(targY)+1)&&(Math.abs(this._y)&gt;=Math.abs(targY)-1)) {
			trace('inside');
			if(ts.dragger.released == true) {
				trace('delete');
				delete this.onEnterFrame;
			}
		}
	}
}

```

[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 1:51pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/5 "2003-07-15T13:51:35Z")

</div>

Math.round returns a value. simply doing Math.round by itself is pointless if it’s not passed to a variable.

```auto
Math.round(this._y -= Math.round((this._y-targY)/5));

```

makes no difference from

```auto
this._y -= Math.round((this._y-targY)/5);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 1:55pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/6 "2003-07-15T13:55:32Z")

</div>

That makes sense, because it makes no difference if I take Math.round out of that line and run the script. So what do you think would make this thing not blurry font? :toad:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 3:06pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/7 "2003-07-15T15:06:08Z")

</div>

How does this look?

[AS]

ts.dragger.onPress = function() {  
this.released = false;  
startDrag(this, false, this.\_x, 0, this.\_x, ts.theMask.\_height-this.\_height);  
// The scrolling animation  
ts.theText.y = ts.theText.\_y; // \<\<---------------new  
ts.theText.onEnterFrame = function() {  
trace(“enterframe”);  
scrollAmount = (this.\_height - (ts.theMask.\_height/1.3))/(ts.theMask.\_height - ts.dragger.\_height);  
// Adjust the height of the dragger to reflect the amount of content available to see  
ts.dragger.\_height = 30;  
// Set a new target y position  
targY = -ts.dragger.\_y\*scrollAmount;  
this.y -= (this.y-targY)/5; // \<\<---------------new

```
        this._y = Math.round(this.y); // &lt;&lt;---------------new
		//
		trace(Math.abs(this._y)+' = '+Math.abs(targY));
		trace(Math.abs(this._y)+'&lt;='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'&gt;='+Math.abs(targY-1));
		if ( (Math.abs(this._y)&lt;=Math.abs(targY)+1)&&(Math.abs(this._y)&gt;=Math.abs(targY)-1)) {
			trace('inside');
			if(ts.dragger.released == true) {
				trace('delete');
				delete this.onEnterFrame;
			}
		}
	}
}

```

[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 15, 2003, 3:07pm UTC](https://forum.kirupa.com/t/help-with-math-round/25652/8 "2003-07-15T15:07:18Z")

</div>

I think you mean:

```auto
this._y = Math.round(this._y);

```

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 4:18am UTC](https://forum.kirupa.com/t/help-with-math-round/25652/9 "2003-07-16T04:18:26Z")

</div>

I’m not sure…:moustache
