The Daily Click ::. Forums ::. Klik Coding Help ::. Getting rid of extra decimal places
 

Post Reply  Post Oekaki 
 

Posted By Message

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
31st October, 2008 at 14:48:58 -

I told MMF2 to turn (1/3) into a string. It then displays 0.33333333333. I just want it to display 0.33. How do I do that?

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
31st October, 2008 at 15:10:07 -

I suspect there's an easier way, but what the heck...

Val(Left$(Str$( >Original Value< ), 1+Len(Str$(Int( >Original Value< )))+ >Number of Decimal Places< ))

If the value is always less than 10 you could just replace everything after the comma with a fixed number, at least.

Hey, I should snippetize that

Image Edited by the Author.

 
n/a

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
31st October, 2008 at 22:20:16 -

In the object properties, I believe.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
1st November, 2008 at 00:14:40 -

See, I knew there'd be an easier way
That's using a counter of course.

 
n/a

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
1st November, 2008 at 01:53:58 -

Hmm.. does that code work with numbers that don't have decimal places? Because sometimes it's 1/3, sometimes 1/2, sometimes 1/1, etc I thought there'd be an easier way to, like one of those extensions or commands I never noticed.

Peblo, the program divides it in the expression editor, not a counter. And then puts it into a text string. I don't think that value handling is in the text string properties. I suppose I could put it into a temporary counter, pull it out, put the next one into a counter, etc, but that's gonna add about 3 more actions per loop and a few bugs along the way

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
1st November, 2008 at 02:02:20 -

I found the "easier" solution. Let's say X is the 1/3, 1/2 or whatever.

Round(X*100)/100.0


Replace 100 and 100.0 with 1000 and 1000.0 for 3 digits after decimal point, and so on.

It's ugly, but it works and is a bit more elegant than Sketchy's method. Just in case anyone is searching for a solution to the same problem in the future.

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
1st November, 2008 at 02:48:00 -

That's a nice simple solution
Mine actually does something a bit different anyway. It limits the *maximum* nuber of decimal places, so "1" would still be "1", not "1.00" for example.

 
n/a

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
1st November, 2008 at 09:12:14 -

Mine also makes "1" appear as "1", not "1.00". But you have to divide it by 1.00 otherwise it won't work because of the really wierd way MMF handles integers and doubles.

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image
   

Post Reply



 



Advertisement

Worth A Click