units-of-measurement

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

旧时模样 提交于 2019-11-27 11:53:46
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 first? @function strip-unit($number) { // magic code here... } @warn strip-unit(16px); // 16 -- UPDATE: You should never actually need to use this function. Sass math is very smart about units, and I have never seen a use-case in which stripping units was a better option than simply using correct math to get what you need. See the Sass issue thread

Converting bytes to megabytes

寵の児 提交于 2019-11-27 09:15:30
问题 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 respected authority (like W3C, ISO, NIST, etc) to clarify which megabyte is a true megabyte. Can anyone cite a source that explicitly explains how this calculation is done? Bonus question: if #2 is a megabyte what are #1 and #3 called? BTW: Hard drive

preferred mechanism to attach a type to a scalar?

情到浓时终转凉″ 提交于 2019-11-27 08:36:10
问题 [ edit: changed meters/yards to foo/bar; this isn't about converting meters to yards. ] What's the best way to attach a type to a scalar such as a double ? The typical use-case is units-of-measure (but I'm not looking for an actual implementation, boost has one). This would appear to be a simple as: template <typename T> struct Double final { typedef T type; double value; }; namespace tags { struct foo final {}; struct bar final {}; } constexpr double FOOS_TO_BARS_ = 3.141592654; inline

F# Units of measure - 'lifting' values to float<something>

不羁岁月 提交于 2019-11-27 07:15:06
问题 When importing numbers from a csv file, I need to convert them to floats with unit. Currently I do this with an inline function: data |> List.map float |> List.map (fun n -> n * 1.0<m>) But I'm wondering if there is a more elegant way to do this - or do I have to create my own 'units' module with conversion functions? What would be really nice would be something like this, but I doubt it's possible... data |> List.map float |> List.map lift<m> This is the opposite of my previous question (How

Unit Conversion in Python

时光怂恿深爱的人放手 提交于 2019-11-27 05:03:58
问题 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 units: http://pypi.python.org/pypi/units/ and quantities: http://pypi.python.org/pypi/quantities/ However I'm not sure the best way to go. From what I can tell, quantities is more complex, but includes a better initial list of units. 回答1: I applaud use of explicit units in scientific

Which jsr-275 units implementation should be used? [closed]

喜你入骨 提交于 2019-11-27 02:18:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . JSR 275 seems to be in a rejected state. JScience seems to have an implementation and there seems to be unitsofmeasure. Are there any other open source implementations? Which package is jsr-275 compliant and easy to use. 回答1: Since the JSR-275 has been rejected the javax namespace cannot be used and has been

How do I convert pt to sp?

萝らか妹 提交于 2019-11-27 00:42:02
问题 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 should be used for type). 回答1: The problem is that it depends on the density. Really, they're not good measurements to try to compare. Points : There are 12 points in a pica, 6 picas per inch, so 72 (more accurately 72.27) points per inch. Device

Does setWidth(int pixels) use dip or px?

别等时光非礼了梦想. 提交于 2019-11-26 23:21:00
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. Daniel Lew It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is in TypedValue.applyDimension() . Here's an example of how to convert dips to px in code: // Converts 14 dip into its equivalent px Resources r = getResources(); int px = Math.round(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 14,r.getDisplayMetrics())); The correct way to obtain a constant number of DIPs in code is to

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

和自甴很熟 提交于 2019-11-26 21:37:28
(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 widths of certain elements. The illustrious Googlites had specified a number of table cols using the rare 'ex' unit. width: 22ex; At first I was stumped ("what's an 'ex'?"), then it came back to me: I seem to remember something from years ago when first I was learning about CSS. From the CSS3 spec : [The ex unit is] equal to the used x-height of the

Units of measure in C# - almost

时光怂恿深爱的人放手 提交于 2019-11-26 19:25:54
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 Length { public interface ILength : IUnit { } public class m : ILength { } public class mm : ILength { } public class ft : ILength { } } public class Mass { public interface IMass : IUnit { } public class kg : IMass { } public class g : IMass { } public class lb : IMass { } } public class UnitDouble<T> where T : IUnit { public readonly double Value; public