Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Need to convert pixel values into percentage values.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Mar 14, 2016 4:14 PM Last Post By: Linden ROTH
karthik thirumo...

Posts: 23
Registered: 9/26/13
Need to convert pixel values into percentage values.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2016 7:17 AM
Hello,
I want to convert the containers & components tlhw (top , left , height , width) pixel values into percentage value. I'm going to use those percentage values in both WEB & Desktop (with different screen resolutions). So, based on the screen resolution , I will calculate the 'tlhw' value again. Can any one help to achieve this ??
I have tried but when converting percentage to pixel , i'm getting some difference there.
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Need to convert pixel values into percentage values.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2016 8:53 AM   in response to: karthik thirumo... in response to: karthik thirumo...
karthik thirumoorthi wrote:

Hello,
I want to convert the containers & components tlhw (top , left ,
height , width) pixel values into percentage value. I'm going to use
those percentage values in both WEB & Desktop (with different screen
resolutions). So, based on the screen resolution , I will calculate
the 'tlhw' value again. Can any one help to achieve this ?? I have
tried but when converting percentage to pixel , i'm getting some
difference there.

You will run into rounding errors, that cannot be helped. Pixel units
are integer, percentages can be floating-point values. Also,
percentages relative to what? Screen *dimensions*?

--
Peter Below
TeamB
karthik thirumo...

Posts: 23
Registered: 9/26/13
Re: Need to convert pixel values into percentage values.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 14, 2016 12:23 AM   in response to: Peter Below in response to: Peter Below
Yes, it is related screen dimensions.

Peter Below wrote:
karthik thirumoorthi wrote:

Hello,
I want to convert the containers & components tlhw (top , left ,
height , width) pixel values into percentage value. I'm going to use
those percentage values in both WEB & Desktop (with different screen
resolutions). So, based on the screen resolution , I will calculate
the 'tlhw' value again. Can any one help to achieve this ?? I have
tried but when converting percentage to pixel , i'm getting some
difference there.

You will run into rounding errors, that cannot be helped. Pixel units
are integer, percentages can be floating-point values. Also,
percentages relative to what? Screen *dimensions*?

--
Peter Below
TeamB
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Need to convert pixel values into percentage values.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 14, 2016 4:13 PM   in response to: karthik thirumo... in response to: karthik thirumo...
karthik thirumoorthi wrote:
Yes, it is related screen dimensions.

Don't store as percentage but as 100,000ths (OR MORE) ie not 10% but a 10,000th

so that a screen dim of 999px on a screen 2000px is not 50% but 49,950 (out of 100,000) you'll still get some rounding error issues but trivial
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02