Home > Blockchain >  How to convert a one digit number to a two digit number by prepending 0?
How to convert a one digit number to a two digit number by prepending 0?

Time:10-04

How to convert a one digit double value, for example, 1.27 to 01.27.

And if the number is 12.27 then it should be 12.27 itself.

CodePudding user response:

I think something like this might do for you:

void main() {
  print((1.27).toString().padLeft(2, '0'));
  print((12.27).toString().padLeft(2, '0'));
}

CodePudding user response:

import 'package:intl/intl.dart';

NumberFormat formatter = new NumberFormat("00.00");
print(formatter.format(1.27));

result : 01.27

CodePudding user response:

if you simply want to print the result, this might be what you need.

void main(){
  double no = 12.27;
  if(no.toInt() <10 && no.toInt() > 0){
    print("0$no");
  }else{
    print(no);
  }
} 
  • Related