标签: units-of-measurement

是否可以在 sass 中向无单位数字添加(动态)单位?

首先,我知道要将无单位值转换为有单位的值,我可以将无单位值乘以单个单位:

$value: 25 * 1px; // 25px
Run Code Online (Sandbox Code Playgroud)

但是我想知道当单位是动态时是否有任何方法可以做到这一点。

$unit: rem;
$value: 23;

.Box {
  // Try interpolation
  $united-value: #{$value}#{$unit};
  value: $united-value; // Appears to be correct
  // Check it is actually a number using unitless 
  check: unitless($united-value); // $number: "23rem" is not a number for `unitless'
}
Run Code Online (Sandbox Code Playgroud)

显然,如果我要计算 的值,$unit 1rem我可以像第一个示例中那样相乘,但是有没有办法用裸单位值来做到这一点。

萨斯迈斯特在这里

[编辑] 正如 @zessx 正确指出的那样,CSS 不关心类型,并且在这种情况下会以相同的方式处理字符串和数字值。但是,在附加单位后,我需要对该值执行操作。

[编辑]我不知道如何才能更清楚。我不想要/需要一个在幕后使用乘法的函数。我已经知道它是如何工作的以及如何做到这一点。我感兴趣是否有一种方法可以获取无单位值和单位并从中得到统一的数字。

有没有一种方法可以将它px作为一个数字并且可以对其进行数学运算?任何向我展示如何采取和做同样的事情的答案都没有回答我所问的问题。2222px1px22

sass multiplication units-of-measurement

4
推荐指数
1
解决办法
1669
查看次数

将扩展方法添加到带有测量单位的记录

为什么这有效:

type Money = 
   { Amount : decimal } with

   member inline m.gotMoney : bool =
      m.Amount > 0M
Run Code Online (Sandbox Code Playgroud)

但这并不

type MoneyUOM<[<Measure>]'currency> = 
   { Amount : decimal<'currency> } with

   member inline m.gotMoney : bool =
      m.Amount > 0M<_>
Run Code Online (Sandbox Code Playgroud)

相反,我得到error FS0339: The signature and implementation are not compatible because the type parameter in the class/signature has a different compile-time requirement to the one in the member/implementation

f# inline units-of-measurement f#-4.0

4
推荐指数
1
解决办法
81
查看次数

在 Swift 3 中设置中长测量符号

在 Swift 中,当我创建自定义单位时,我只能定义一个符号。内置单元可以有短、中、长单元。如何为自定义单位设置其他单位样式?

extension UnitEnergy {
    static let footPounds = UnitEnergy(symbol: "ft-lbs", converter: UnitConverterLinear(coefficient: 1))
}

var test = Measurement<UnitEnergy>( value: 10, unit: .footPounds)
var formatter = MeasurementFormatter()

formatter.locale = Locale(identifier: "es")

formatter.unitStyle = .short
print( formatter.string(from: test))

formatter.unitStyle = .medium
print( formatter.string(from: test))

formatter.unitStyle = .long
print( formatter.string(from: test))

formatter.unitOptions = .providedUnit

formatter.unitStyle = .short
print( formatter.string(from: test))

formatter.unitStyle = .medium
print( formatter.string(from: test))

formatter.unitStyle = .long
print( formatter.string(from: test))
Run Code Online (Sandbox Code Playgroud)

输出:

10 J
10 J
10 julios
10 ft-lbs …
Run Code Online (Sandbox Code Playgroud)

units-of-measurement swift swift3

4
推荐指数
1
解决办法
774
查看次数

units::set_units() 无法识别变量中的单位

如何units从变量中将单位读入包中?我得到了错误...not recognised by udunits。MWE如下:

\n\n
library(units)\nmeasurements <- runif(10)\nunitsofmeasurement <- "mm"\nset_units(measurements, unitsofmeasurement)\n
Run Code Online (Sandbox Code Playgroud)\n\n

返回错误

\n\n
Error: In \xe2\x80\x98unitsofmeasurement\xe2\x80\x99, \xe2\x80\x98unitsofmeasurement\xe2\x80\x99 is not recognized by udunits.\n
Run Code Online (Sandbox Code Playgroud)\n\n

但以下有效:

\n\n
set_units(measurements, "mm")\n
Run Code Online (Sandbox Code Playgroud)\n

r units-of-measurement

4
推荐指数
1
解决办法
670
查看次数

RStudio 和 Travis CI 构建检查不匹配 (libudunits2.so)

特拉维斯CI检测并没有被发现问题,Build > CheckRStudio我的lares图书馆(在Github上找到作为laresbernardo /拉雷斯)。根据 Travis CI 的说法,我最后一次“通过”提交实际上是一个错字更改,因此库的代码应该不是问题;因此,当我devtools::check()为库运行时,我会收到R CMD check succeeded一条包含 0 个错误、警告或注释的好消息。

我已经尝试过消息建议的内容和其他内容:

  • brew install udunits在终端 (macOS) 中运行
  • 通过 CRAN 安装库 install.packages(units)
  • 并通过 Github (dev) 与 devtools::install_github("r-quantities/units", args="--configure-args='--with-udunits2-lib=/usr/local/lib'")
  • devtools::install_github("r-quantities/units", args="--configure-args='--with-udunits2-include=/usr/include/udunits2'")

这是 Travis CI 日志的结尾,也可以在这里找到:https : //travis-ci.org/laresbernardo/lares

(...)
checking for ut_read_xml in -ludunits2... no
configure: error: in `/tmp/RtmpITNXhh/R.INSTALL3d3b9a0f951/units':
configure: error: 
--------------------------------------------------------------------------------
  Configuration failed because libudunits2.so was not found. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: …
Run Code Online (Sandbox Code Playgroud)

build github units-of-measurement rstudio travis-ci

4
推荐指数
1
解决办法
330
查看次数

转发地点 - 时区,计量单位等

在代码中应该进行哪些转换?客户端,服务器,业务或数据库?

我们目前在数据库中进行时区和度量单位的转换,性能正在扼杀我们,并希望移动逻辑.您认为最佳位置在哪里?

谢谢

timezone datetime units-of-measurement

3
推荐指数
1
解决办法
294
查看次数

如何一般性地删除F#度量单位

我有一些数据操作代码,最后吐出csv.

我开始升级它以在任何地方添加度量单位,但我现在遇到了我的csv函数问题:

val WriteCSV : string -> 'a list array -> 'b list -> string -> unit
Run Code Online (Sandbox Code Playgroud)

(参数是fileName,列数组,列标题,分隔符)

我之前发送[| s; x; y |]到WriteCSV的地方,我现在有一个问题,因为我无法发送[| skm; XMM; 青运|].

我尝试编写一个通常删除度量单位的函数,但它不起作用.

let removeUnit (n:float<_>) = n/1.0<_>
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  • 为什么不起作用?
  • 可以使它工作吗?
  • 有没有其他方法可以解决这个特殊问题?

f# units-of-measurement

3
推荐指数
1
解决办法
797
查看次数

使用Python数量时消除单位

我正在使用Python的大量包.我想知道如何在没有单位的情况下得到数量的数值.

即,如果我有

E = 5.3*quantities.joule
Run Code Online (Sandbox Code Playgroud)

我想达到5.3.我知道我可以简单地除以"不受欢迎的"单位,但希望有更好的方法来做到这一点.

python units-of-measurement

3
推荐指数
1
解决办法
2830
查看次数

方法超载与计量单位

我正在努力用F#试图创建cos接受单位角度的重载.

这是我的代码:

[<Measure>] type rad
[<Measure>] type deg
let toRad(x:float<deg>) =
    (float x) * 3.14159265 / 180.0
    |> LanguagePrimitives.FloatWithMeasure<rad>
let cos (angle: float<rad>) = cos(float angle)
let cos (angle: float<deg>) = cos(toRad angle) // get duplicate definition of cos here
Run Code Online (Sandbox Code Playgroud)

编译器抱怨最后一行的cos重复定义.

f# trigonometry units-of-measurement

3
推荐指数
1
解决办法
117
查看次数

是否可以通过F#中的度量单位标记创建区分联合?

是否可以通过F#中的测量单位标签创建区分联合类型?

我想写... 如下:

type DomainObject =
| Pixel           of int
| ScaledPixel     of int
| Centimeter      of float
| Unset

let var1 = 10<px> // should equal: let var1 = Pixel(10)
let var2 = 0<us>  // should equal: let var2 = Unset

let process sth =
  match sth with
  | Pixel(p) -> ...
  | Centimeter(c) -> ...
  // etc.
Run Code Online (Sandbox Code Playgroud)

使用NumericLiterals这样的事情是可能的.但是,人们只能使用Neil P.表示的少量文字.

f# units-of-measurement discriminated-union

3
推荐指数
1
解决办法
203
查看次数