# comparing numbers

## Recommended Posts

ok, so here is a synopsis of what I'm trying to do.

I have a field called last gift, (\$xx.xx) is how it is formatted. what I need to do is to make it \$25 if its less than \$25.00.

I also need it not to show the .00 if they are .00, but if it is something like \$25.40 to make it show that.

here is where I am and I can't get it to work, it always returns \$25 no matter the value.

CustTypeSplit=var1.split(".")

Number=CustTypeSplit

decimal=CustTypeSplit

if (Number<='25')

return "25";

else

if (decimal ==.00)

return Number;

else return Number +"."+decimal;

any help would be greatly appreciated.

##### Share on other sites

ok, so here is a synopsis of what I'm trying to do.

I have a field called last gift, (\$xx.xx) is how it is formatted. what I need to do is to make it \$25 if its less than \$25.00.

I also need it not to show the .00 if they are .00, but if it is something like \$25.40 to make it show that.

here is where I am and I can't get it to work, it always returns \$25 no matter the value.

CustTypeSplit=var1.split(".")

Number=CustTypeSplit

decimal=CustTypeSplit

if (Number<='25')

return "25";

else

if (decimal ==.00)

return Number;

else return Number +"."+decimal;

any help would be greatly appreciated.

You might give this a try.

```var giftAmount = Field("LASTGIFT").replace(/\\$/g, "");

return '\$25.00';
else

##### Share on other sites

Number=CustTypeSplit

decimal=CustTypeSplit

return '25.00';

else

if (decimal ==.00)

return Number;

else return Number +"."+decimal;

this wound up working... thank you very much. This forum rocks.

##### Share on other sites

Here's a little one-liner that does the same thing from the replace function. It also truncates the cents when dealing with an even dollar amount.

```return Field("LASTGIFT").replace(/\\$((??!\.00).)*).*/, function(s, p){ return +p < 25 ? '\$25' : '\$' + p; });
```

##### Share on other sites

• 3 weeks later...

this seems really dumb, but I can't get this to work now that some of the data has a decimal, and some does not. basically all I need to do this time is have the return be either a whole dolloar... 25 when the data is 25.00, or when the data is \$25. also need to be 2.05 if the data is 2.05. or 2.10 if the data is 2.10. the rule above works for all of these instances except for the one that's 2.10, because the data comes in as 2.1 and that's what it sees. I know this should be simple, but its driving me nuts at the moment. any help would be appreciated.

thanks

##### Share on other sites

this seems really dumb, but I can't get this to work now that some of the data has a decimal, and some does not. basically all I need to do this time is have the return be either a whole dolloar... 25 when the data is 25.00, or when the data is \$25. also need to be 2.05 if the data is 2.05. or 2.10 if the data is 2.10. the rule above works for all of these instances except for the one that's 2.10, because the data comes in as 2.1 and that's what it sees. I know this should be simple, but its driving me nuts at the moment. any help would be appreciated.

thanks

Well, it doesn't sound like you're trying to achieve the same thing you were in your initial post so I'm not totally surprised that the code doesn't work the way you're expecting it to. Initially, you said you wanted a minimum value of \$25 for each price and to drop the ".00" from even dollar amounts. Now it just sounds like you're asking how to remove the ".00" which doesn't really fall under the topic of "comparing numbers" but is more in line with formatting numbers.

Basically, now you just want to format the price to two decimal places:

```return FormatNumber("0.00", "2.1"); // 2.10
```

And then move the ".00" if present:

```return "FormatNumber("0.00", Field("LASTGIFT")).replace(".00", "");
```

## 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. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×

• #### FusionPro.com

• MarcomCentral
×
• Create New...