Round

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Round

Post by Nakia » Fri May 03, 2013 12:52 am

Hi,

Is there a way when using the Round() function to force it to inlcude the "0's" in its result?
For example.

I have a value that is "212" and I want to to the Round() function to 3 decimal places 3 so I want the value returned at "212.000"
Now, before you ask Yes i konw these are the same value but the reason I want to do this is so the fld I am placing this data in keeps its alignment between each item (Tab Del) consistent.
Note, this is for a reporting application.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Round

Post by Simon » Fri May 03, 2013 1:05 am

Isn't this done by:
set the numberFormat to "#.000"

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Round

Post by sturgis » Fri May 03, 2013 1:55 am

Yeah numberformat is a good way to go, or alternatively look at the format() function.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Round

Post by dunbarx » Fri May 03, 2013 4:12 am

What those guys said.

This goes back to the earliest days of Hypercard. Read up on the "numberFormat" property, especially the use of zeros and hashmarks to format in the desired way. This takes a little practice. Also, pay attention to the fact that a numeric calculation must oftentimes be performed on a value to force it to display as it was ordered to. This may take the form of:

add 0 to yourRecentlyFormattedString

or the monumental:

multiply yourRecentlyFormattedString by 1

This also takes practice.

Craig Newman

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Round

Post by dave_probertGA6e24 » Fri May 03, 2013 12:01 pm

This would also do it:

Code: Select all

put format("%d.000", round( fff )) into ooo
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Round

Post by Nakia » Wed May 08, 2013 12:22 am

dave_probertGA6e24 wrote:This would also do it:

Code: Select all

put format("%d.000", round( fff )) into ooo
Cheers,
Dave
This worked perfect, thanks dave!!!

Post Reply