首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EXCEL -将吨转换为KG不正确

EXCEL -将吨转换为KG不正确
EN

Stack Overflow用户
提问于 2022-01-08 10:09:38
回答 2查看 417关注 0票数 -2

我在MAC上有Excel 365。

我想把“重量单位”转换成另一个“重量单位”。=转换(数字;from_unit;to_unit)

为什么1吨=907公斤?这个应该是1000公斤

代码语言:javascript
复制
Amount  Unit        Amount          Unit
1   ton =>  907,18474   kg
1   kg  =>  1000            g
1   g   =>  1000            mg

正确的转换方式是什么?

谢谢你,艾库特

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-01-08 10:19:41

在大英百科全书中,吨的定义是吨,重量单位在体重系统中等于2,000磅(907.18公斤)在美国的(短吨)和2,240磅(1,016.05公斤)在英国(长吨)。在,大多数其他国家使用的公吨是1,000公斤,相当于2,204.6磅的体重。

Microsoft只支持"ton“和"uk_ton”

票数 1
EN

Stack Overflow用户

发布于 2022-01-09 10:40:00

Excel功能不适用于单位从吨(公制)到其他重量单位的转换。

Excel开箱即用功能:

=Convert(value;from_unit;to_unit)

我想用与Excel相同的属性共享我的(解决方案)解决方案:

=myConvert(value;from_unit;to_unit)

代码语言:javascript
复制
Public Function myConvert(value As Variant, f_unit As String, to_unit As String) As Variant
    Dim conversion As String
    Dim position As Integer
    
    Dim unit_array As Variant
    
    unit_array = Array( _
    "mg_mg", "mg_g", "mg_kg", "mg_t", _
    "g_mg", "g_g", "g_kg", "g_t", _
    "kg_mg", "kg_g", "kg_kg", "kg_t", _
    "t_mg", "t_g", "t_kg", "t_t" _
    )
    
    Dim formula_array As Variant
    
    formula_array = Array( _
    "", "/ 1000", "/ 1000000", "/ 1000000000", _
    "* 1000", "", "/ 1000", "/ 1000000", _
    "* 1000000", "* 1000", "", " / 1000", _
    "* 1000000000", "* 1000000", "* 1000", "" _
     )
    
    conversion = f_unit & "_" & to_unit
    position = array_pos(unit_array, conversion)
 
    value = Replace(value, ",", ".")
    
    If (IsNumeric(value) = False) Then
        myConvert = "not a number"
        Exit Function
    ElseIf (position < 0) Then
        myConvert = "unknown unit"
        Exit Function
    End If
  
    myConvert = Evaluate(value & " " & formula_array(position))
    
End Function


Function array_pos(my_array, my_value)
    array_pos = -1
    
    For ii = LBound(my_array) To UBound(my_array)
        If my_array(ii) = my_value Then 'value found
            array_pos = ii
            Exit For
        End If
    Next
    
End Function

以下是测试结果:

代码语言:javascript
复制
1   t   =   1           t
                
1   t   =   1000            kg
1   t   =   1000000         g
1   t   =   1000000000  mg
                
1   kg  =   0,001           t
1   g   =   0,000001    t
1   mg  =   0,000000001 t
                
1   t   =   unknown unit    x      because x as unit is unknown
y   t   =   not a number    kg     because y is not a number

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70631345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档