Jump to content

Removing Negative characters before a #


JCrocker

Recommended Posts

My data is coming in as -1.01 and to represent a dollar amt savings and I'm trying to return $1.01 I got the dollar symbol by using the change number to currency rule so now I'm getting $-1.01 but I can't get rid of the - sign. Also I'm trying to figure out how to get -.98 in the same field to return as 98¢

 

Also in another field I have -25 to represent a percentage savings and I need to convert it to 25% by removing the - sign and adding the % sign.

 

Any Suggestions

Link to comment
Share on other sites

That works for -1.01 in particular. But how do I apply this rule to the entire external data field many different records and values. The values of less than a dollar that appear in the format of -.98 I need to return as 98¢ and the items of a dollar or more in the format of -1.56 i need to return as $1.56 . Both appear in the same field but different records so I'm guessing the rule must be written to address both?

 

A similar scenario in a different field deals with a percentage savings. The data appears in the format of -27 and I need it to return 27%

Link to comment
Share on other sites

Try something like this in a rule or a function in javascript globals :

lcAmount = "-.98"

 

if (Left(Trim(lcAmount),2) == "-.")

{

//return '¢';

return ReplaceSubstring(lcAmount,"-.","") + '¢';

}

else

{

//return '$';

return '$' + ReplaceSubstring(lcAmount,"-","");

}

 

for the percentage :

 

lcPercent = "-27"

 

return ReplaceSubstring(lcPercent,"-","") + '%';

Link to comment
Share on other sites

In javascript globals it gives me invalid return errors. It seems to want to work in a normal javascript text rule but it only gives me the same return everytime aside from the data. I need to link it to field30 for the dollar/cent amt and field31 for the percentage amt.
Link to comment
Share on other sites

In your rule just replace the following var :

 

lcAmount = Field("field30")

 

same goes for the percentage

 

lcPercent = Field("field31")

 

if you want to go in javascript globals you have to declare the function and call it from any rule

 

rule test with : return fixAmount(Field("amt"))

 

in the javascript globals :

function fixAmount(lcParameterPass)

{

lcAmount = lcParameterPass

 

if (Left(Trim(lcAmount),2) == "-.")

{

//return '¢';

return ReplaceSubstring(lcAmount,"-.","") + '¢';

}

else

{

//return '$';

return '$' + ReplaceSubstring(lcAmount,"-","");

}

 

}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...