Jump to content

Maintain decimal zeros


Recommended Posts

  • 1 year later...
when I preview is looks like:

 

12345.0

 

and the field is ZIP CODE

Assuming the ZIP CODE field contains just the five-digit Zip code in the data, you should just be able to use that field directly in your text frame. I don't think you need to use a JavaScript rule at all.

Link to comment
Share on other sites

Assuming the ZIP CODE field contains just the five-digit Zip code in the data, you should just be able to use that field directly in your text frame. I don't think you need to use a JavaScript rule at all.

In the excel file it is just five digits, but for some reason when I make it a variable field in FP, it comes up with a decimal and 0 (hence 12345.0 instead of 12345). I was wanting to write a rule to get around it and make it display correctly.

 

any thoughts? :)

Link to comment
Share on other sites

In the excel file it is just five digits, but for some reason when I make it a variable field in FP, it comes up with a decimal and 0 (hence 12345.0 instead of 12345). I was wanting to write a rule to get around it and make it display correctly.

How are you bringing the data in from Excel to FusionPro? Are you exporting to a flat file, like a CSV file? If so, that's the input to FusionPro, not the Excel file itself. So, what does the data look like in the flat file? You might need to fix something in Excel so that the CSV file has the data in the correct format.

 

But still, you should be able to do this:

return FormatNumber("00000", Field("ZIP CODE"));

Link to comment
Share on other sites

How are you bringing the data in from Excel to FusionPro? Are you exporting to a flat file, like a CSV file? If so, that's the input to FusionPro, not the Excel file itself. So, what does the data look like in the flat file? You might need to fix something in Excel so that the CSV file has the data in the correct format.

 

But still, you should be able to do this:

return FormatNumber("00000", Field("ZIP CODE"));

as odbc...

 

the problem with this is that we use the same template many times and don't want to have to redo the databases that come all the time :)

 

thanks for the help, I will give it a whirl :D

Link to comment
Share on other sites

  • 7 months later...
How are you bringing the data in from Excel to FusionPro? Are you exporting to a flat file, like a CSV file? If so, that's the input to FusionPro, not the Excel file itself. So, what does the data look like in the flat file? You might need to fix something in Excel so that the CSV file has the data in the correct format.

 

But still, you should be able to do this:

return FormatNumber("00000", Field("ZIP CODE"));

 

I am bringing in a .CSV file that does not keep the trailing zeros, now trying to create an accounting style look to numbers, I need the trailing zeros. I understand the use for the FormatNumber, but is there a way to make a global rule for multiple fields instead of having to create so many rules and variables? Would I really need to go through and create a FormatNumber on each Field?

 

I have something like 152 overall numerical fields that vary in trailing numbers, and like I said, if there is a global functionality to this without having to create a RULE for each Field that would be most excellent. Thanks.

Link to comment
Share on other sites

I am bringing in a .CSV file that does not keep the trailing zeros, now trying to create an accounting style look to numbers, I need the trailing zeros. I understand the use for the FormatNumber, but is there a way to make a global rule for multiple fields instead of having to create so many rules and variables? Would I really need to go through and create a FormatNumber on each Field?

 

I have something like 152 overall numerical fields that vary in trailing numbers, and like I said, if there is a global functionality to this without having to create a RULE for each Field that would be most excellent. Thanks.

You can do something like this in OnRecordStart:

for (var v in FusionPro.Fields)
   FusionPro.Composition.AddVariable(v, FormatNumber("00000", FusionPro.Fields[v]));

This will "inject" new variables for the composition, overriding the original field values.

 

However, this will affect every field in the job, rendering non-numeric fields empty, so you probably want to filter it somehow. Ideally this would be done by field name. I don't know the field names in your job, but it would be something like this:

for (var v in FusionPro.Fields)
{
   if (ToUpper(v).indexOf("ZIP") >= 0)
       FusionPro.Composition.AddVariable(v, FormatNumber("00000", FusionPro.Fields[v]));
}

Or you could do something like this to apply the formatting only to fields which contain nothing but digits:

for (var v in FusionPro.Fields)
{
   if (FusionPro.Fields[v] && FusionPro.Fields[v].search(/\D/) < 0)
       FusionPro.Composition.AddVariable(v, FormatNumber("00000", FusionPro.Fields[v]));
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...