8 Replies Latest reply on Mar 1, 2017 2:43 PM by HenryRobinson

# Converting any number into a negitive percent

I have a filed that I want to let the user enter a number and have it converted into a negative percent. Some example entries and the result I would like.

20 > -20%

-20 > -20%

.2 > -20%

-.2 > -20%

I am currently using the following script trigger on exit and seems to be working for the most part. if the user enters -1 it give -100% but the user can still enter 1 and -.01 to get -1% . What I am hoping though is that there is a cleaner way to do this and one that might work even for the 1%. I need to do this on lots of fields. Any suggestions are welcome.

# change to percent

if [MyField ≥ 0]

Set Field [MyField; MyField * .01]

Else if [ MyField = -1]

Set Field [MyField; -1]

Else if [ MyField < - .999999999999999999999999999]

Set Field [MyField; MyField * .01]

# Change to negative

if [MyField =-1]

# do nothing

Else if [ MyField > 0]

Set Field [MyField; MyField * -1]

• ###### 1. Re: Converting any number into a negitive percent

Get rid of the script and make it an auto-enter calculation. Not only will this then work for your field no matter how many different layouts might be used to edit the value, you can use the case function to make it cleaner and easier to read/maintain. I'm also not sure that your script is really correct. You are multiplying any value greater than zero by 0.01--which would take a value of 0.01 and make it 0.0001 or 0.01%.

I'd use:

let ( s = abs ( self ) ;

Case ( S > 1 ; self * 0.01 ;

S

) * -1

)

Make sure to clear the "do not replace existing value..." check box.

• ###### 2. Re: Converting any number into a negitive percent

Would be nice to know whether you need that -20% for display only or also plan to use it in further calculations.

The "negative" thing: If it's a "discount" type of value you can put it on the layout with a preceding "-". In order to use it in calcs, you don't need it to be negative, you can use the ABS() of it - no matter what the user enters - to do your calcs. It's a discount, you know it has to be negative, so you can plan around it.

• ###### 3. Re: Converting any number into a negitive percent

I like this but if the user enters a -20 it shows up as 20%

• ###### 4. Re: Converting any number into a negitive percent

I do use it in further calculation. I think to understand 100% what you are saying I will need to do some reading up on what ABS() function dose exactly.

• ###### 5. Re: Converting any number into a negitive percent

No it does not. It should still be -20%. Note the use of the absolute value function to make all entered values positive at the start before later multiplying by -1 to make it negative.

• ###### 6. Re: Converting any number into a negitive percent

I must be doing something wrong. I first tried to type in the calculation by hand and it seemed to work except for negative entries. I then tried to copy the calculation in and that had the same result. I then made a new database made one number filed pasted in the code and again same result. what could I be doing wrong?

• ###### 7. Re: Converting any number into a negitive percent

It doesn't work  because I goofed. Use this version:

let ( s = abs ( self ) ;

Case ( S > 1 ; s * 0.01 ;

S

) * -1

)

1 of 1 people found this helpful
• ###### 8. Re: Converting any number into a negitive percent

That worked thank you. I had never used abs() very useful.