Questions tagged [units-of-measurement]

Units of Measure are compile-time attributes that can be associated with numeric values, typically used to indicate length, volume, mass, and so on.

A Unit of Measure is information that can be associated with a numeric value, typically used to indicate length, volume, mass, and so on. This information is used in numerous applications ranging across engineering, science, physics, and many other disciplines.

If this information is stored as a compile-time attribute, then a compiler can verify arithmetic relationships of values across the numeric computations to have the proper units, therefore preventing programming errors.

See also Units Dimensions And Dimensionless Numbers.

607 questions
6334
votes
32 answers

What is the difference between px, dip, dp, and sp?

What is the difference between the units of measure px, dip, dp, and sp?
535
votes
10 answers

Should I use px or rem value units in my CSS?

I am designing a new website and I want it to be compatible with as much browsers and browser settings as possible. I am trying to decide what unit of measurement I should use for the sizes of my fonts and elements, but am unable to find a…
user1218247
143
votes
10 answers

Converting bytes to megabytes

I've seen three ways of doing conversion from bytes to megabytes: megabytes=bytes/1000000 megabytes=bytes/1024/1024 megabytes=bytes/1024/1000 Ok, I think #3 is totally wrong but I have seen it. I think #2 is right, but I am looking for some…
User1
  • 39,458
  • 69
  • 187
  • 265
102
votes
7 answers

Does setWidth(int pixels) use dip or px?

Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example, does setWidth(100) set the a view's width to 100 dips or 100 pxs? Thanks.
98
votes
6 answers

What is the value of the css 'ex' unit?

(Not to be confused with Xunit, a popular .Net unit testing library.) Today in a fit of boredom I started inspecting Gmails DOM (yes, I was very bored). Everything looked pretty straightforward until I noticed an interesting specification on the…
Joel
  • 19,175
  • 2
  • 63
  • 83
78
votes
4 answers

How to set the maximum width of a column in CSS Grid Layout?

What I want to achieve: Using CSS Grid Layout, to have a page with a right column which size is derived from its content, but only up to 20% of the window width. How I thought it would work: div { border-style: solid; } #container { …
WoJ
  • 27,165
  • 48
  • 180
  • 345
65
votes
14 answers

Units of measure in C# - almost

Inspired by Units of Measure in F#, and despite asserting (here) that you couldn't do it in C#, I had an idea the other day which I've been playing around with. namespace UnitsOfMeasure { public interface IUnit { } public static class…
Benjol
  • 63,995
  • 54
  • 186
  • 268
61
votes
7 answers

How do I know which is the default measure system (imperial or metric) on iOS?

How do I know which is the default measure system (imperial or metric) on iOS ? How do I get this preference from the device settings, so I know what to display in my app ? thanks
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
57
votes
13 answers

Unit Conversion in Python

I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both…
Chris Drackett
  • 1,248
  • 2
  • 10
  • 22
53
votes
3 answers

How do you strip the unit from any number in SASS?

I know you can strip units from numbers in SASS when you know the unit before-hand like this: $number: 16px; $without-unit: 16px / 1px; @warn $without-unit; // 16 But is it possible to strip the unit from a number without knowing what the unit is…
jordanbtucker
  • 5,768
  • 2
  • 30
  • 43
49
votes
6 answers

How do I calculate the temperature in celsius returned in openweathermap.org JSON?

I'm getting the weather for a city using openweathermap.org. The jsonp call is working and everything is fine but the resulting object contains the temperature in an unknown unit: { //... "main": { "temp": 290.38, // What unit of…
48
votes
8 answers

When specifying a 0 value in CSS, should I explicitly mark the units or omit?

This is more of a 'philosophy' argument, but I'd like to know what the recommended practice here. I'm not setting it up as a Wiki yet in case there is an 'official' answer. Obviously, there is no difference between 0px and 0em or whatever, so one…
Uri
  • 88,451
  • 51
  • 221
  • 321
46
votes
3 answers

Does java -Xmx1G mean 10^9 or 2^30 bytes?

And in general, are the units used for the -Xmx, -Xms and -Xmn options ("k", "M" and "G", or the less standard possibilities "K", "m" or "g") Binary prefix multiples (i.e. powers of 1024), or are they powers of 1000? The manuals say they represent…
nealmcb
  • 12,479
  • 7
  • 66
  • 91
45
votes
2 answers

Can F# units of measure be implemented in OCaml?

F# has a units of measure capability (there's more detail in this research paper). [] type unit-name [ = measure ] This allows units to be defined such as: type [] USD type [] EUR And code to be written as: let dollars =…
Darren
  • 2,888
  • 1
  • 23
  • 34
43
votes
6 answers

How do I convert pt to sp?

I am a visual designer, working on an android design and I"m trying to spec my PSD file for our engineers. I cannot seem to find any documentation regarding the conversion of point size to SP for the type in any Android documentation. (Just that SP…
Megatallica
  • 431
  • 1
  • 4
  • 3
1
2 3
40 41