/*
 * @Author: XianKaiQun
 * @Date: 2020-09-29 16:05:01
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-10-14 10:43:14
 * @Description: 
 */

import 'package:flutter/widgets.dart';

///数字快速转换成TextStyle
extension NumToTextStyle on num {
  ///数字快速转换成TextStyle
  ///```dart
  ///Text(
  /// '文本',
  /// style:12.asSizeStyle
  ///)
  ///Text(
  /// '文本',
  /// style:TextStyle(fontSize:12)
  ///)
  ///
  ///
  ///```
  TextStyle get asSizeStyle {
    return TextStyle(
      fontSize: this as double?,
    );
  }
}

extension NumToParseFloat on num {
  ///去除小数点后面二维的0
  ///```dart
  ///1.000.parseFloat() //1
  ///1.010.parseFloat() //1.01
  ///```
  num? parseFloat() {
    final str = this.toString().replaceFirst(RegExp(r'(\.0*|0+)$'), '');
    return num.tryParse(str);
  }

  ///去除小数点后面二维的0,返回的是String
  ///```dart
  ///1.000.parseFloat() //1
  ///1.010.parseFloat() //1.01
  ///```
  String? parseFloatString() {
    final that = this.parseFloat();
    return that?.toString();
  }
}
