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
42
votes
5 answers

Converting units in R

I would like to convert from imperial units to metric and vice versa in R. How do I go about doing that? If there is no current way of doing that, how can I create a package that would?
thequerist
  • 1,774
  • 3
  • 19
  • 27
33
votes
6 answers

Using locale settings to detect wheter to use imperial units

I'm working on an app that wants to display lengths either in centimeters (cm) or in inches("). Is there a way to select the right unit from the locale? In any event I'm also going to put in an option so that the user can to override the locale…
vidstige
  • 12,492
  • 9
  • 66
  • 110
32
votes
3 answers

How can I manage units in pandas data?

I'm trying to figure out if there is a good way to manage units in my pandas data. For example, I have a DataFrame that looks like this: length (m) width (m) thickness (cm) 0 1.2 3.4 5.6 1 7.8 9.0 …
ajwood
  • 18,227
  • 15
  • 61
  • 104
26
votes
23 answers

Do you use "kibibyte" as a unit of measurement in your programs?

For decades, in the field of computing (except disk manufacturers), a KB (kilobyte) was understood to mean 1024 bytes. In the past few years, there has been a movement to use KiB ("kibibyte") to mean 1024 bytes, and change the meaning of kilobyte to…
Steve Hanov
  • 11,316
  • 16
  • 62
  • 69
22
votes
3 answers

What is the unit of measurement in Xcode

This might sound silly but when i'm working with sizes in Xcode, the total frame size is equal to 320 * 568 ( width * height ). I'm fine with that. But the resolution of the phone is actually different. The iphone 4S is 640*960 & the 5 and next…
Gil Sand
  • 5,802
  • 5
  • 36
  • 78
22
votes
4 answers

Cooking Units in Java

Are there any open source libraries for representing cooking units such as Teaspoon and tablespoon in Java? I have only found JSR-275 (https://jcp.org/en/jsr/detail?id=275) which is great but doesn't know about cooking units.
gregm
  • 12,019
  • 7
  • 56
  • 78
21
votes
4 answers

Is there a standard pythonic way to treat physical units / quantities in python?

Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions…
Philipp der Rautenberg
  • 2,212
  • 3
  • 25
  • 39
20
votes
4 answers

Units of measurement in C++

I'm working on a game engine, and currently I'm stuck designing the IO system. I've made it so, the engine itself doesn't handle any file formats, but rather lets the user implement anything he wants by creating a *.dll file with appropriately named…
Paweł Stawarz
  • 3,952
  • 2
  • 17
  • 26
18
votes
5 answers

Best unit for font-sizes in CSS

What are the advantages & disadvantages of each? em, px, % and pt ? My current choice are percentages, the only reason is because I can globally change the font-size of all elements, just by modifying the font size on the root element (body)
Alex
  • 66,732
  • 177
  • 439
  • 641
18
votes
3 answers

How granular are CSS rem units?

I am developing a scalable mobile/desktop friendly website using CSS rem units based on the average viewport size of the site. I have been setting rem sizes as low as 0.001rem for certain padding and margins, which is working fine in my Firefox…
darkAsPitch
  • 1,855
  • 4
  • 23
  • 35
18
votes
1 answer

How to prevent vh-units from ignoring the scrollbar?

I am working on a page layout with a horizontal scrollbar. I have some panels with fixed widths in a horizontal order, which should all have the viewport height. I decided to test the vh unit to do that. .panel { height: 100vh; } This is working…
Afterlame
  • 1,188
  • 2
  • 13
  • 32
17
votes
2 answers

How do F# units of measure work?

Has anyone had a chance to dig into how F# Units of Measure work? Is it just type-based chicanery, or are there CLR types hiding underneath that could (potentially) be used from other .net languages? Will it work for any numerical unit, or is it…
Emperor XLII
  • 13,014
  • 11
  • 65
  • 75
16
votes
5 answers

Compile-time constraints for strings in F#, similar to Units of Measure - is it possible?

I'm developing a Web application using F#. Thinking of protecting user input strings from SQL, XSS, and other vulnerabilities. In two words, I need some compile-time constraints that would allow me discriminate plain strings from those representing…
Be Brave Be Like Ukraine
  • 7,596
  • 3
  • 42
  • 66
16
votes
1 answer

jq and Math functions

I'm retrieving JSON from a real estate database. jq makes it easy to pull out the separate properties/values, but some of the values are in inconvenient units. For example, the LotSize variable is in square feet (need to divide by 43560 to get…
richb-hanover
  • 1,015
  • 2
  • 12
  • 23
15
votes
2 answers

WPF Units and Code-Behind

Recently I discovered WPF supports different measurement units in XAML. Besides default DIPs, there is also support for pixels, inches and centimeters (as far as I know). This allows designer to write XAML such as this:
1
2
3
40 41