Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting a field as percentage shows incorrect value 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I have a field on a form and I have set it to display as percentage with two decimal places.

However, when a value of 1.01% is displayed it is showing as 101%.

Why?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Because it is correct. You are storing the value 1.01, which is 101%. You would need to store the value .0101 to show as 1.01%
 
I'd try to use this format:
"0.00\%"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I do not believe you can do that. If you put the literal character "\" followed by a percent Access will remove it. On your form just put a percent symbol next to the textbox. In a query or report use a calculated control to display it using the format function.
 
The bigger question is why do you want to store a value that is not a percent and display as such. If you are doing any calculations you would have to then convert it to a percent by dividing by 100 throughout the whole database. It seems to me someday this is going to bite you especially if exporting to other sources.
 
It is akin to storing a Date (which is a number) as text and then having to CONVERT the TEXT to a NUMBER in order to do math!

STORE the number as it is USED and DISPLAY as VIEWED (formated).

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
10% is a conventional representation (display text) of 0.10 (real value).
 
PHV - how do you go about altering a table and updating a load of apps and reports to handle a number that has now been divided by 100?

Is that considered productive refactoring?

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
If your app is already in production then don't alter anything just for a display problem.
I suppose all the math (ie divide by 100) is already made by code or expressions.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I suppose all the math (ie divide by 100) is already made by code or expressions.
Exactly! You live and learn, but as many 'views' do not format the data either , hence storing it in a value that could easily be displayed, it's not just a matter of removing the math part from code / expressions, it would break a plethora of views also!

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
I suppose all the math (ie divide by 100) is already made by code or expressions.
Exactly! You live and learn, but as many 'views' do not format the data either , hence storing it in a value that could easily be displayed, it's not just a matter of removing the math part from code / expressions, it would break a plethora of views also!

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Oh, it's so sad. You're quite right that if a whole system has been built by people who don't understand that a percentage is actually just a fraction, and that Microsoft Office products have been capable of displaying a fraction (0.11) as a percentage (11%) at the click of a button for decades, then you have a horrible mess that will probably never be changeable. It's nearly as bad as those systems (and I've been guilty of them - shame!) which store time-periods sometimes as hours, sometimes days, sometimes minutes, and then have to shuffle things around every time they need to add the period to a date.

PHV and Skip are utterly right. Untangling percentage disasters is one of my least favourite jobs. Usually I'm doing it in Excel where someone will have a vast formula peppered with /100's and *100's and strange things to deal with the fact they have several factors used arithmetically as a fraction but stored in percentage form. To my mind it's as daft as storing the number of bananas you have in microbananas, and then remembering to divide by 1000000 in all banana-oriented calculations. Very often formulae with all these /100's have typos and mistakes, but have been "fixed" at some point by someone realising the answer was a few decimal places wrong, and empirically multiplying or dividing at the end to make it right.

A big consideration is readability. Your system with all its percentages will confuse outsiders.
 
Yup, as I said you live and learn, and usually too late!

It's no big deal, it was only as i was developing a new app and applying new skills learned on my OU course, utilising MVC principles and so attempting to use the 'view' correctly and formatting unbound fields using the in-built property settings that this arose.

I think we can all be guilty of having legacy 'crap' in the systems we develp over the years and as your knowledge and experience increases so does the quality of your work.

Oh and of course PHV and Skip are utterly right, they are rarely anything else ;-)





"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top