Jump to content

Padding Numbers with 0s


This topic is 5728 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I need to pad numbers with zeros at the end when they have no numbers, to the second decimal place.

Example:

Entered by user

1

1.5

2.25

6.05

4.8

2.

All these number should be padded with zeros, if needed, and should look like:

1.00

1.50

2.25

6.05

4.80

2.00

Does anyone know of a good function that will take these numbers and pad them?

Link to comment
Share on other sites

I moved your question from the Custom Function Topic Area to here for a couple of reasons. One, to create a Custom Function requires the Developer in v7 and Advance in v8, and you are reflecting just standard v8. The other reason is, this doesn't require a Custom Function.

In order to use leading and trailing zeros (after the decimal), you need to make your field Text. FileMaker drops the leading and trailing zeros after the decimal, in the number fields.

If you just want to see the formatting, then you can format the field in Layout to show the zeros that are trailing.

HTH

Lee

Link to comment
Share on other sites

I moved your question from the Custom Function Topic Area to here for a couple of reasons. One, to create a Custom Function requires the Developer in v7 and Advance in v8, and you are reflecting just standard v8. The other reason is, this doesn't require a Custom Function.

In order to use leading and trailing zeros (after the decimal), you need to make your field Text. FileMaker drops the leading and trailing zeros after the decimal, in the number fields.

If you just want to see the formatting, then you can format the field in Layout to show the zeros that are trailing.

HTH

Lee

Thanks Lee,

But I need the numbers to stay in a text field, because these numbers are mixed with text. So I cannot just change the field to a number and set the layout attribute to display two decimal places. I need some kind of function that will pad these numbers even if they are text.

Link to comment
Share on other sites

If the numbers are within existing text, is there always just ONE set of numbers in the text field? Because if not, you probably DO need a Custom Function or at least a Let[] which recurses. How will you separate when a number is a text number and a, umm, number number?

UPDATE: For instance, how will calculation know that "called me back 1 time" should be treated differently than "paid 1 for product"?

Edited by Guest
Added update
Link to comment
Share on other sites

why not use a substitute calculation. It may have some flaws, but it is worth a try.

Substitute ( TextField ;

[".0 " ; ".00 "];

[".1 " ; ".10 "];

[".2 " ; ".20 "];

[".3 " ; ".30 "];

[".4 " ; ".40 "];

[".5 " ; ".50 "];

[".6 " ; ".60 "];

[".7 " ; ".70 "];

[".8 " ; ".80 "];

[".9 " ; ".90 "]

)

HTH

Lee

Link to comment
Share on other sites

why not use a substitute calculation. It may have some flaws, but it is worth a try.

Substitute ( TextField ;

[".0 " ; ".00 "];

[".1 " ; ".10 "];

[".2 " ; ".20 "];

[".3 " ; ".30 "];

[".4 " ; ".40 "];

[".5 " ; ".50 "];

[".6 " ; ".60 "];

[".7 " ; ".70 "];

[".8 " ; ".80 "];

[".9 " ; ".90 "]

)

HTH

Lee

This did not work. This function does not take into account two situations

1. If someone enters a whole number (without decimals), such as: 1, 34 or 2

2. If someone enters a number that does not need to be padded, such as: 2.25 or 3.42

If the numbers are within existing text, is there always just ONE set of numbers in the text field? Because if not, you probably DO need a Custom Function or at least a Let[] which recurses. How will you separate when a number is a text number and a, umm, number number?

UPDATE: For instance, how will calculation know that "called me back 1 time" should be treated differently than "paid 1 for product"?

LaRetta,

I am sorry, but I have explained this incorrectly. I am not taking a text field with text and numbers, but I am taking numbers (from a number field) or numbers (from a text field) and just the numbers. Then formating them (padding) and placing them into text fields.

Haven't you guys ever needed to place some formated numbers into a block of text or into some kind of text field. When you have to do this, you must pad the numbers. No matter if they are coming from a number field or a text field.

So basically all I need is some kind of function that will take a single number and pad it, if needed, and give me the results so i can place it anywhere I want.

Thanks

Link to comment
Share on other sites

I know you feel frustrated, but I do not like the response you just posted.

I'm sure we have a solution, but you have not explained your situation good enough.

It now appears that all you are trying to do is to export you number field as text and have it format with the appropriate number of trailing zeros. Your explaination up to now led me (us) do believe this data was already in a text field with other text.

If that is what you mean, then there has been dozens of post about Number Format as Text.

Do a search and you will see many.

Lee

Link to comment
Share on other sites

I saw nothing out of line in the response.

Hi Ray,

"But I need the numbers to stay in a text field, because these numbers are mixed with text. "

... this is what threw me off. Well, there are thousands of posts on formatting numbers because, yes, it is needed inside calculations or for export and it isn't the easiest concept to grasp. This one works. But if you read all the posts, it takes a very complex one to cover every possible situation. This one doesn't (obviously) add a thousands separator. And it breaks if you have negative cents.

Let (

[

num = Int ( theNumber ) ;

cents = Right ( "00" & theNumber * 100 ; 2 )

]

;

num & "." & cents

)

I'm a bit too wasted to find some killer calcs for you so you'll have to do some hunting if this doesn't meet your needs. :wink2:

LaRetta

Link to comment
Share on other sites

  • Newbies

OK, keep in mind that I am very new to Filemaker (I used to program 15 years ago in DOS-based Clarion, but here goes)....so be kind in your comments.

I had the same problem when setting up a payroll program (modeled after my still-functioning Clarion program). I just formatted the entry and display fields to 2 decimal places after defining the field as a number. I think this accomplishes what you are after.

Link to comment
Share on other sites

Hi and welcome to the Forum,

Actually, the formatting a number in layout mode, is often forgotten in our quest to make things more complicate then they need to be. :giggle:

However, in this case the poster was looking to export a [color:blue]number field as [color:blue]TEXT, and retain the trailing zeros, that you see when you format a number field, however, when you export a number, FileMaker will drop the trailing zeros following the decimal.

The common practice in version 7/8 is to apply a calculation, such as suggested by LaRetta above. If you do a search of the forum, you will see several different calculation that have been posted in the past, most are for previous versions, were one calculation did [color:red]NOT fit all situations.

HTH

Lee

Edited by Guest
clean it up a little
Link to comment
Share on other sites

This topic is 5728 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.