#鸿蒙学习大百科#如何将一个数字转化为科学计数法显示?

如何将一个数字转化为科学计数法显示?

HarmonyOS
2024-10-29 09:48:18
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
莫名瞄一眼
// 导入模块
import { intl } from '@kit.LocalizationKit';

@Entry
@Component
struct Index {
  @State str: string = ''

  build() {
    Column() {
      Text(this.str)
        .fontSize(30)
        .margin(20)
      Button("点击").onClick(() => {
        // 用科学计数法显示数字
        let numberFormat1 = new intl.NumberFormat('zh-CN', { notation: 'scientific', maximumSignificantDigits: 3 });
        this.str = numberFormat1.format(123400); // formattedNumber1: 1.23E5

      })
    }
    .height("100%")
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

分享
微博
QQ
微信
回复
2024-10-29 16:10:44


相关问题
如何将张图片转化为PixelMapElement
11119浏览 • 1回复 待解决