Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Data formatting question - percentages

Avatar

Avatar
Level 2
csbendz
Level 2

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
csbendz
Level 2

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
csbendz
Level 2

17-02-2009

I am trying to get an output in a percentage form, eg 89% when a user types in 89 and/or 0.89



I've been trying to format it on my own for some time with no luck- can anyone help?

Replies

Avatar

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
Steve_L_Walker
Level 9

20-02-2009

Carly,



There are a number of options. If you define the field as a Decimal Field or a Numeric there are many pattern options for Display and Edit (on the object Field tab, click Patterns, and go to the Display or Edit tab).



If you want to use a Text Field then life becomes a little more complicated. The following script could be put on the exit event. If the field is not null it will check that the value entered is a number. If it is a number it will convert the string accordingly.



if (!(this.formattedValue.length == 0 && this.editValue.length == 0)) {

if (isNaN(this.rawValue)) {

xfa.host.messageBox("This is not a number.");

}

else {

var myNum = parseFloat(this.rawValue);

if (myNum < 1) {

myNum = myNum * 100;

}

this.rawValue = myNum.toString() + "%";

}

}



Please test this thoroughly. It is late...



Steve

Avatar

Avatar
Level 2
csbendz
Level 2

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
csbendz
Level 2

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
View profile
csbendz
Level 2

20-02-2009

This is helpful, thank you.



My follow up question is: how can I enable the user to enter a whole number, and have the percentage sign just automatically appear? (As of right now, the user has to enter a decimal in order for the percent to display. I don't want the user to have to enter a decimal - it's not the end of the world, but it isn't ideal.) I have been using numerical fields.

Avatar

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 1
Level 9
Steve_L_Walker
Level 9

Likes

197 likes

Total Posts

1,435 posts

Correct Reply

212 solutions
Top badges earned
Validate 1
Boost 50
Boost 5
Boost 3
Boost 25
View profile
Steve_L_Walker
Level 9

20-02-2009

Carly,



Add the display pattern



num{(zz9'%')}



This enables a value of 1-999 to be entered and displayed with a trailing percent sign. For example, enter 5 and the result is 5%, enter 100 and the result is 100%.



Steve