The Daily Click ::. Forums ::. Klik Coding Help ::. Money Math Dollar and Cents.
 

Post Reply  Post Oekaki 
 

Posted By Message

Mr. Hexagon



Registered
  20/10/2010
Points
  1608
13th April, 2012 at 13/04/2012 02:43:00 -

Hello!

Here's my problem. I am making a piece of software that asks users to input a dollar amount.
Math is performed on this dollar amount, and a new dollar amount is outputted.

Currently, I am obtaining the dollar amount via edit object.
But a problem arises when entering an amount with cents. So something like 4.58.
MMF drops the .58 when grabbing it from the Edit Object

HALP!?

 
misterhexagon.blogspot.com

GameDragon



Registered
  23/08/2004
Points
  7
13th April, 2012 at 13/04/2012 03:08:23 -

Before doing any math with decimal values, MMF2 needs to know that you're trying to use decimals.
The expression:
Alterable Value A("OBJ") + Alterable Value B("OBJ")
... will probably round off.

However:
0.0 + Alterable Value A("OBJ") + Alterable Value B("OBJ")
... should give you want you want.

Edited by GameDragon

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th April, 2012 at 13/04/2012 03:19:47 -

Never use the "get numeric value" expression, as that always returns an integer.
Instead, you need to say: Val( Edittext$( "Edit Box" ) )
It's dumb, I know.

 
n/a

Mr. Hexagon



Registered
  20/10/2010
Points
  1608
13th April, 2012 at 13/04/2012 05:57:35 -

Both tips helped. Thank you GameDragon and Sketchy!

I unfortunately ran into another problem.
To post the new dollar amount into a new edit box, I'm using "convert float to string" conversion, which is all fine and dandy.
However, when I go to export it as a .swf Flash file, I am alerted by the fact that this conversion is unavailable.

Is there a way around this dilema you can suggest?

 
misterhexagon.blogspot.com

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th April, 2012 at 13/04/2012 14:13:57 -

As long as the values are always positive, you can just use a simple string function:

"$"+Str$(Int(Number))+"."+Right$("0"+Left$(Str$(Round((Number mod 1)*100)), 2), 2)

Note: Remember to always use the full precision value for any actual calculations - only use the above function when displaying the value.
If you need negative values as well, you'll probably need to write a few more lines of code.

Edited by Sketchy

 
n/a
   

Post Reply



 



Advertisement

Worth A Click