#鸿蒙学习大百科#如何用用紧凑的格式显示数字?

如何用用紧凑的格式显示数字?

HarmonyOS
2024-10-29 09:49:40
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
鹈鹕说蟹蟹你
// 导入模块
import { intl } from '@kit.LocalizationKit';

@Entry
@Component
struct Index {
  @State str: string = ''
  aboutToAppear(): void {
    let numberFormat2 = new intl.NumberFormat('zh-CN', { notation: 'compact', compactDisplay: 'short' });
    this.str = numberFormat2.format(123400); // formattedNumber2: 12万
  }
  build() {
    Column() {
      Text(this.str)
        .fontSize(30)
        .margin(20)
    }
    .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.
分享
微博
QQ
微信
回复
2024-10-29 15:41:21
相关问题
#鸿蒙学习大百科#ArkTS如何生成xml?
1200浏览 • 1回复 待解决