【问题标题】:Convert integer to string in lua?在lua中将整数转换为字符串?
【发布时间】:2018-10-02 21:19:52
【问题描述】:

我已经看到很多将字符串转换为整数的答案,但是如何将整数转换为字符串呢?当我尝试microseconds.toString() 时出现以下错误:attempt to index upvalue 'microseconds' (a number value)

请注意,这是在运行 os 4.5.0.1180 的 ti-nspire 上

感谢您提供的任何帮助!

【问题讨论】:

  • 尝试字符串(微秒)
  • ... 或 string.format("%d", microseconds) 但在串联 "foo" .. microseconds 中,数字应强制转换为字符串。

标签: string types lua integer ti-nspire


【解决方案1】:

来自https://www.lua.org/manual/5.1/manual.html#pdf-tostring

tostring (e)

接收任何类型的参数并将其转换为 格式合理的字符串。为了完全控制数字的方式 转换后,使用string.format。如果 e 的元表有“__tostring” 字段,然后 tostring 以 e 作为参数调用相应的值, 并使用调用的结果作为其结果。

tostringNSpire Lua Scripting API Reference Guide 的第 1 章 第 1 页中提到...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 2014-12-03
    • 2010-12-27
    • 2012-02-21
    • 2010-12-31
    相关资源
    最近更新 更多