Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Sidney de Koning

Hi Jim,

In the Number class there is are a couple of functions to help you.  
You want a function called toFixed().


so if you do Number(total).toFixed(2); You get the result you want :)

This is pure AS3 though,

Hope this helps,

Sid

On Jan 27, 2009, at 9:45 AM, jimmi wrote:

Goodmorning, i am trying to make a formula that makes for example  
30.60 of 30.6. So I need it to add a 0.


This is the formula I am using now.
total = Number(Number(600) / 100 * Number(5.1))

I have tried all sorts of additions to the formula to try to get it  
to make 30.60 of 30.6. But no luck


Anyone here who knows how to make the formula add a 0?

Best regards,
Jim
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Cor
That would be:


num.toFixed(2));

HTH
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jimmi
Sent: dinsdag 27 januari 2009 9:45
To: Flash Coders List
Subject: [Flashcoders] [AS in general] Question corcerning a math formula 

Goodmorning, i am trying to make a formula that makes for example 30.60 of
30.6. So I need it to add a 0. 

This is the formula I am using now.
total = Number(Number(600) / 100 * Number(5.1))

I have tried all sorts of additions to the formula to try to get it to make
30.60 of 30.6. But no luck

Anyone here who knows how to make the formula add a 0?

Best regards,
Jim
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.14/1917 - Release Date: 26-1-2009
18:37

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread jimmi
Ah snap, i need it for AS2, is there any alternative for that?

Best regards,
Jim

On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
sid...@funky-monkey.nl wrote:
 Hi Jim,

 In the Number class there is are a couple of functions to help you. You want
 a function called toFixed().

 so if you do Number(total).toFixed(2); You get the result you want :)

 This is pure AS3 though,

 Hope this helps,

 Sid

 On Jan 27, 2009, at 9:45 AM, jimmi wrote:

 Goodmorning, i am trying to make a formula that makes for example 30.60 of
 30.6. So I need it to add a 0.

 This is the formula I am using now.
 total = Number(Number(600) / 100 * Number(5.1))

 I have tried all sorts of additions to the formula to try to get it to
 make 30.60 of 30.6. But no luck

 Anyone here who knows how to make the formula add a 0?

 Best regards,
 Jim
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread allandt bik-elliott (thefieldcomic.com)
you need to add it to a string and work out if the extra 0 is needed (maybe
with the modulo (%) comparison operator), in as2, and then manually add the
zero to the string when you output to your textfield

do a search for as2 timers / digital clocks and you'll come across the
technique

a

On Tue, Jan 27, 2009 at 9:05 AM, jimmi cho...@gmail.com wrote:

 Ah snap, i need it for AS2, is there any alternative for that?

 Best regards,
 Jim

 On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
 sid...@funky-monkey.nl wrote:
  Hi Jim,
 
  In the Number class there is are a couple of functions to help you. You
 want
  a function called toFixed().
 
  so if you do Number(total).toFixed(2); You get the result you want :)
 
  This is pure AS3 though,
 
  Hope this helps,
 
  Sid
 
  On Jan 27, 2009, at 9:45 AM, jimmi wrote:
 
  Goodmorning, i am trying to make a formula that makes for example 30.60
 of
  30.6. So I need it to add a 0.
 
  This is the formula I am using now.
  total = Number(Number(600) / 100 * Number(5.1))
 
  I have tried all sorts of additions to the formula to try to get it to
  make 30.60 of 30.6. But no luck
 
  Anyone here who knows how to make the formula add a 0?
 
  Best regards,
  Jim
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
  Sidney de Koning - be a geek, in rockstar style!
  Flash / AIR Developer @ www.funky-monkey.nl
  Technical Writer @ www.insideria.com
 
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Sidney de Koning

Hi Jimmi,

Look at this then,

To truncate Numbers in Actionscript:
Three decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber =  Math.round(yourNumber *1000)/1000;
// Outputs 23.263

Two decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber = Math.round(yourNumber *100)/100;
// Outputs 23.26

One decimal:
var yourNumber:Number = 23.263636453737383838383838;

yourNumber = Math.round(yourNumber *10)/10;
// Outputs 23.2

and if you want to do it even nicer you do it like this:


function round(number:Number, precision:Number):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
trace(Math.round(decimalPlaces * number) / decimalPlaces)
return Math.round(decimalPlaces * number) / decimalPlaces;
}

round(2.5678, 2);

Hope this helps,

Sid


On Jan 27, 2009, at 10:05 AM, jimmi wrote:


Ah snap, i need it for AS2, is there any alternative for that?

Best regards,
Jim

On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
sid...@funky-monkey.nl wrote:

Hi Jim,

In the Number class there is are a couple of functions to help you.  
You want

a function called toFixed().

so if you do Number(total).toFixed(2); You get the result you want :)

This is pure AS3 though,

Hope this helps,

Sid

On Jan 27, 2009, at 9:45 AM, jimmi wrote:

Goodmorning, i am trying to make a formula that makes for example  
30.60 of

30.6. So I need it to add a 0.

This is the formula I am using now.
total = Number(Number(600) / 100 * Number(5.1))

I have tried all sorts of additions to the formula to try to get  
it to

make 30.60 of 30.6. But no luck

Anyone here who knows how to make the formula add a 0?

Best regards,
Jim
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Ian Thomas
Or, split the string on the last '.', look at the length of the string
after the dot, add 0s until it has a length of 2...

Ian

On Tue, Jan 27, 2009 at 10:12 AM, allandt bik-elliott
(thefieldcomic.com) alla...@gmail.com wrote:
 you need to add it to a string and work out if the extra 0 is needed (maybe
 with the modulo (%) comparison operator), in as2, and then manually add the
 zero to the string when you output to your textfield

 do a search for as2 timers / digital clocks and you'll come across the
 technique

 a

 On Tue, Jan 27, 2009 at 9:05 AM, jimmi cho...@gmail.com wrote:

 Ah snap, i need it for AS2, is there any alternative for that?

 Best regards,
 Jim

 On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
 sid...@funky-monkey.nl wrote:
  Hi Jim,
 
  In the Number class there is are a couple of functions to help you. You
 want
  a function called toFixed().
 
  so if you do Number(total).toFixed(2); You get the result you want :)
 
  This is pure AS3 though,
 
  Hope this helps,
 
  Sid
 
  On Jan 27, 2009, at 9:45 AM, jimmi wrote:
 
  Goodmorning, i am trying to make a formula that makes for example 30.60
 of
  30.6. So I need it to add a 0.
 
  This is the formula I am using now.
  total = Number(Number(600) / 100 * Number(5.1))
 
  I have tried all sorts of additions to the formula to try to get it to
  make 30.60 of 30.6. But no luck
 
  Anyone here who knows how to make the formula add a 0?
 
  Best regards,
  Jim
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
  Sidney de Koning - be a geek, in rockstar style!
  Flash / AIR Developer @ www.funky-monkey.nl
  Technical Writer @ www.insideria.com
 
  ___
  Flashcoders mailing list
  Flashcoders@chattyfig.figleaf.com
  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread allandt bik-elliott (thefieldcomic.com)
would that work for the number 2:20 tho?

doesn't flash remove zeros at the end of decimal values?

a

On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning
sid...@funky-monkey.nlwrote:

 Hi Jimmi,

 Look at this then,

 To truncate Numbers in Actionscript:
 Three decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber =  Math.round(yourNumber *1000)/1000;
 // Outputs 23.263

 Two decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber = Math.round(yourNumber *100)/100;
 // Outputs 23.26

 One decimal:
 var yourNumber:Number = 23.263636453737383838383838;

 yourNumber = Math.round(yourNumber *10)/10;
 // Outputs 23.2

 and if you want to do it even nicer you do it like this:


 function round(number:Number, precision:Number):Number
 {
var decimalPlaces:Number = Math.pow(10, precision);
trace(Math.round(decimalPlaces * number) / decimalPlaces)
return Math.round(decimalPlaces * number) / decimalPlaces;
 }

 round(2.5678, 2);

 Hope this helps,

 Sid



 On Jan 27, 2009, at 10:05 AM, jimmi wrote:

  Ah snap, i need it for AS2, is there any alternative for that?

 Best regards,
 Jim

 On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
 sid...@funky-monkey.nl wrote:

 Hi Jim,

 In the Number class there is are a couple of functions to help you. You
 want
 a function called toFixed().

 so if you do Number(total).toFixed(2); You get the result you want :)

 This is pure AS3 though,

 Hope this helps,

 Sid

 On Jan 27, 2009, at 9:45 AM, jimmi wrote:

  Goodmorning, i am trying to make a formula that makes for example 30.60
 of
 30.6. So I need it to add a 0.

 This is the formula I am using now.
 total = Number(Number(600) / 100 * Number(5.1))

 I have tried all sorts of additions to the formula to try to get it to
 make 30.60 of 30.6. But no luck

 Anyone here who knows how to make the formula add a 0?

 Best regards,
 Jim
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread allandt bik-elliott (thefieldcomic.com)
cheers fella

a

On Tue, Jan 27, 2009 at 10:39 AM, Sidney de Koning
sid...@funky-monkey.nlwrote:

 Hi allandt,

 2:20 is not a number :) its a string. i think what flash tries to do is
 convert it to a number but fails and convert it to a string
 what you could do is strip out any : or , and replace it with a . (dot) and
 then pass it to the round function.

 You can use this class for it, its AS2:
 http://www.funky-monkey.nl/blog/2006/10/29/replace-string-class/

 Have fun with it!

 Sid


 On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com)
 wrote:

  would that work for the number 2:20 tho?

 doesn't flash remove zeros at the end of decimal values?

 a

 On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning
 sid...@funky-monkey.nlwrote:

  Hi Jimmi,

 Look at this then,

 To truncate Numbers in Actionscript:
 Three decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber =  Math.round(yourNumber *1000)/1000;
 // Outputs 23.263

 Two decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber = Math.round(yourNumber *100)/100;
 // Outputs 23.26

 One decimal:
 var yourNumber:Number = 23.263636453737383838383838;

 yourNumber = Math.round(yourNumber *10)/10;
 // Outputs 23.2

 and if you want to do it even nicer you do it like this:


 function round(number:Number, precision:Number):Number
 {
  var decimalPlaces:Number = Math.pow(10, precision);
  trace(Math.round(decimalPlaces * number) / decimalPlaces)
  return Math.round(decimalPlaces * number) / decimalPlaces;
 }

 round(2.5678, 2);

 Hope this helps,

 Sid



 On Jan 27, 2009, at 10:05 AM, jimmi wrote:

 Ah snap, i need it for AS2, is there any alternative for that?


 Best regards,
 Jim

 On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
 sid...@funky-monkey.nl wrote:

  Hi Jim,

 In the Number class there is are a couple of functions to help you. You
 want
 a function called toFixed().

 so if you do Number(total).toFixed(2); You get the result you want :)

 This is pure AS3 though,

 Hope this helps,

 Sid

 On Jan 27, 2009, at 9:45 AM, jimmi wrote:

 Goodmorning, i am trying to make a formula that makes for example 30.60

 of
 30.6. So I need it to add a 0.

 This is the formula I am using now.
 total = Number(Number(600) / 100 * Number(5.1))

 I have tried all sorts of additions to the formula to try to get it to
 make 30.60 of 30.6. But no luck

 Anyone here who knows how to make the formula add a 0?

 Best regards,
 Jim
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___

 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Sidney de Koning

Oh Allandt i misread, sorry.

Yes flash does remove the zero at the end of decimal values.
But then you only want to use this function to display (in a textfield  
or something) and not to calcualte with it,
because calculating with double zeroes is the same calucalting with a  
zero :) ie 4 * 2.0 == 4 *2.


To fix it do this (AS3 code):

function round(pValue:Number, precision:int):String {
var intVal:Number = Math.floor(pValue);
var finalLength : int = intVal.toString().length + 1 + precision;
var baseString : String = pValue.toString().substr(0, finalLength);
if(baseString.length == intVal.toString().length) {
baseString += .;
}
while(baseString.length  finalLength) {
baseString += 0;
}
return baseString;
}

If there is someone on this list who would like to convert this  
function to AS2 to help Jimmi that would be awesome :)


Cheers,

Sid


On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com)  
wrote:



would that work for the number 2:20 tho?

doesn't flash remove zeros at the end of decimal values?

a

On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning
sid...@funky-monkey.nlwrote:


Hi Jimmi,

Look at this then,

To truncate Numbers in Actionscript:
Three decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber =  Math.round(yourNumber *1000)/1000;
// Outputs 23.263

Two decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber = Math.round(yourNumber *100)/100;
// Outputs 23.26

One decimal:
var yourNumber:Number = 23.263636453737383838383838;

yourNumber = Math.round(yourNumber *10)/10;
// Outputs 23.2

and if you want to do it even nicer you do it like this:


function round(number:Number, precision:Number):Number
{
  var decimalPlaces:Number = Math.pow(10, precision);
  trace(Math.round(decimalPlaces * number) / decimalPlaces)
  return Math.round(decimalPlaces * number) / decimalPlaces;
}

round(2.5678, 2);

Hope this helps,

Sid



On Jan 27, 2009, at 10:05 AM, jimmi wrote:

Ah snap, i need it for AS2, is there any alternative for that?


Best regards,
Jim

On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
sid...@funky-monkey.nl wrote:


Hi Jim,

In the Number class there is are a couple of functions to help  
you. You

want
a function called toFixed().

so if you do Number(total).toFixed(2); You get the result you  
want :)


This is pure AS3 though,

Hope this helps,

Sid

On Jan 27, 2009, at 9:45 AM, jimmi wrote:

Goodmorning, i am trying to make a formula that makes for example  
30.60

of
30.6. So I need it to add a 0.

This is the formula I am using now.
total = Number(Number(600) / 100 * Number(5.1))

I have tried all sorts of additions to the formula to try to get  
it to

make 30.60 of 30.6. But no luck

Anyone here who knows how to make the formula add a 0?

Best regards,
Jim
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___

Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread jimmi
Thanks guys, i now have some more insight into this matter.

Best regards,
Jim

On Tue, Jan 27, 2009 at 12:01 PM, allandt bik-elliott
(thefieldcomic.com) alla...@gmail.com wrote:
 cheers fella

 a

 On Tue, Jan 27, 2009 at 10:39 AM, Sidney de Koning
 sid...@funky-monkey.nlwrote:

 Hi allandt,

 2:20 is not a number :) its a string. i think what flash tries to do is
 convert it to a number but fails and convert it to a string
 what you could do is strip out any : or , and replace it with a . (dot) and
 then pass it to the round function.

 You can use this class for it, its AS2:
 http://www.funky-monkey.nl/blog/2006/10/29/replace-string-class/

 Have fun with it!

 Sid


 On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com)
 wrote:

  would that work for the number 2:20 tho?

 doesn't flash remove zeros at the end of decimal values?

 a

 On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning
 sid...@funky-monkey.nlwrote:

  Hi Jimmi,

 Look at this then,

 To truncate Numbers in Actionscript:
 Three decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber =  Math.round(yourNumber *1000)/1000;
 // Outputs 23.263

 Two decimals:
 var yourNumber:Number = 23.263636453737383838383838;
 yourNumber = Math.round(yourNumber *100)/100;
 // Outputs 23.26

 One decimal:
 var yourNumber:Number = 23.263636453737383838383838;

 yourNumber = Math.round(yourNumber *10)/10;
 // Outputs 23.2

 and if you want to do it even nicer you do it like this:


 function round(number:Number, precision:Number):Number
 {
  var decimalPlaces:Number = Math.pow(10, precision);
  trace(Math.round(decimalPlaces * number) / decimalPlaces)
  return Math.round(decimalPlaces * number) / decimalPlaces;
 }

 round(2.5678, 2);

 Hope this helps,

 Sid



 On Jan 27, 2009, at 10:05 AM, jimmi wrote:

 Ah snap, i need it for AS2, is there any alternative for that?


 Best regards,
 Jim

 On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
 sid...@funky-monkey.nl wrote:

  Hi Jim,

 In the Number class there is are a couple of functions to help you. You
 want
 a function called toFixed().

 so if you do Number(total).toFixed(2); You get the result you want :)

 This is pure AS3 though,

 Hope this helps,

 Sid

 On Jan 27, 2009, at 9:45 AM, jimmi wrote:

 Goodmorning, i am trying to make a formula that makes for example 30.60

 of
 30.6. So I need it to add a 0.

 This is the formula I am using now.
 total = Number(Number(600) / 100 * Number(5.1))

 I have tried all sorts of additions to the formula to try to get it to
 make 30.60 of 30.6. But no luck

 Anyone here who knows how to make the formula add a 0?

 Best regards,
 Jim
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___

 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 Sidney de Koning - be a geek, in rockstar style!
 Flash / AIR Developer @ www.funky-monkey.nl
 Technical Writer @ www.insideria.com

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] [AS in general] Question corcerning a math formula

2009-01-27 Thread Sidney de Koning

If it works, it works :)
Try converting it to a function so you can reuse it later.

Happy coding :)

Sid

On Jan 27, 2009, at 12:29 PM, jimmi wrote:


I now have this :

total= String(Number(600) / 100 * Number(5.1)); 
cash = newArray;
cash = total.split(.);
if (cash.length == 1)
{
 total+= .00;
}
else if (cash[cash.length - 1].length == 1)
{
 total+= 0;
}

It's doing the job.

On Tue, Jan 27, 2009 at 12:14 PM, Sidney de Koning
sid...@funky-monkey.nl wrote:

Oh Allandt i misread, sorry.

Yes flash does remove the zero at the end of decimal values.
But then you only want to use this function to display (in a  
textfield or

something) and not to calcualte with it,
because calculating with double zeroes is the same calucalting with  
a zero

:) ie 4 * 2.0 == 4 *2.

To fix it do this (AS3 code):

function round(pValue:Number, precision:int):String {
  var intVal:Number = Math.floor(pValue);
  var finalLength : int = intVal.toString().length + 1 +  
precision;
  var baseString : String = pValue.toString().substr(0,  
finalLength);

  if(baseString.length == intVal.toString().length) {
  baseString += .;
  }
  while(baseString.length  finalLength) {
  baseString += 0;
  }
  return baseString;
}

If there is someone on this list who would like to convert this  
function to

AS2 to help Jimmi that would be awesome :)

Cheers,

Sid


On Jan 27, 2009, at 11:26 AM, allandt bik-elliott  
(thefieldcomic.com) wrote:



would that work for the number 2:20 tho?

doesn't flash remove zeros at the end of decimal values?

a

On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning
sid...@funky-monkey.nlwrote:


Hi Jimmi,

Look at this then,

To truncate Numbers in Actionscript:
Three decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber =  Math.round(yourNumber *1000)/1000;
// Outputs 23.263

Two decimals:
var yourNumber:Number = 23.263636453737383838383838;
yourNumber = Math.round(yourNumber *100)/100;
// Outputs 23.26

One decimal:
var yourNumber:Number = 23.263636453737383838383838;

yourNumber = Math.round(yourNumber *10)/10;
// Outputs 23.2

and if you want to do it even nicer you do it like this:


function round(number:Number, precision:Number):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
trace(Math.round(decimalPlaces * number) / decimalPlaces)
return Math.round(decimalPlaces * number) / decimalPlaces;
}

round(2.5678, 2);

Hope this helps,

Sid



On Jan 27, 2009, at 10:05 AM, jimmi wrote:

Ah snap, i need it for AS2, is there any alternative for that?


Best regards,
Jim

On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning
sid...@funky-monkey.nl wrote:


Hi Jim,

In the Number class there is are a couple of functions to help  
you. You

want
a function called toFixed().

so if you do Number(total).toFixed(2); You get the result you  
want :)


This is pure AS3 though,

Hope this helps,

Sid

On Jan 27, 2009, at 9:45 AM, jimmi wrote:

Goodmorning, i am trying to make a formula that makes for  
example 30.60


of
30.6. So I need it to add a 0.

This is the formula I am using now.
total = Number(Number(600) / 100 * Number(5.1))

I have tried all sorts of additions to the formula to try to  
get it to

make 30.60 of 30.6. But no luck

Anyone here who knows how to make the formula add a 0?

Best regards,
Jim
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___


Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @ www.funky-monkey.nl
Technical Writer @ www.insideria.com

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Sidney de Koning - be a geek, in rockstar style!
Flash / AIR Developer @