Skip to content

toStringAsFixed giving me unexpected result in some case. #142522

@7ANV1R

Description

@7ANV1R

Steps to reproduce

  1. Define a double value like this
    double value1 = 1.845;
  2. try to round two digit after decimal like
    String inString1 = value1.toStringAsFixed(2);
  3. then print the value

Expected results

1.85

Actual results

1.84

Code sample

Code sample
void main() {
  double value1 = 1.845;
  String inString1 = value1.toStringAsFixed(2);
// expected 1.85 actual 1.84
  print(inString1);
  
  double value2 = 2.845;
  String inString2 = value2.toStringAsFixed(2);
// expected 2.85 actual 2.85
  print(inString2);
  
  double value3 = 7.845;
  String inString3 = value3.toStringAsFixed(2);
// expected 7.85 actual 7.84
  print(inString3);
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.8, on macOS 14.2.1 23C71 darwin-arm64, locale
    en-AE)
    • Flutter version 3.16.8 on channel stable at
      /Users/rivnatrs/Documents/SoftFile/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 67457e669f (2 weeks ago), 2024-01-16 16:22:29 -0800
    • Engine revision 6e2ea58a5c
    • Dart version 3.2.5
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/rivnatrs/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 14
      (API 34) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS
      14.2.1 23C71 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google
      Chrome 120.0.6099.234

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions