Maintain decimal zeros

Recommended Posts

How do I maintain two decimals if result is ***.00 or ***.x0?

Adding ***.00 + ***.00 getting yyy (no decimal, no zeros). Tried adding a ".00" at the end, but if there was a ***.50, my trailing ".00" cancatenated and became, yyy.5.00

Share on other sites

Are you using the FormatNumber() function?

`return FormatNumber("0.00", YourData);`

Share on other sites

Eric,

I was mis-using "FormatNumber" and your suggestion made me take a fresh look. Works great now.

Thanks,

Andy

Share on other sites

• 1 year later...

I'm confused... and new to JS

var ZIP CODE = ZIP ();

return FormatNumber("0", ZIP );

I want it to return no decimal or decimal places...

any help greatly appreciated!

Share on other sites

What does you data for zip code look like and what is the name of the field it is provided in?
Share on other sites

What does you data for zip code look like and what is the name of the field it is provided in?

when I preview is looks like:

12345.0

and the field is ZIP CODE

thanks!

Share on other sites

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.

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?

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"));`

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

Share on other sites

works great, thanks Dan!
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.

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)
```

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)
}```

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)
}```

Archived

This topic is now archived and is closed to further replies.

×

• FusionPro.com

• MarcomCentral
×
• Create New...