| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 String fourDigits(int n) { |
| 6 int absN = n.abs(); |
| 7 String sign = n < 0 ? "-" : ""; |
| 8 if (absN >= 1000) return "$n"; |
| 9 if (absN >= 100) return "${sign}0$absN"; |
| 10 if (absN >= 10) return "${sign}00$absN"; |
| 11 if (absN >= 1) return "${sign}000$absN"; |
| 12 } |
| 13 |
| 5 String threeDigits(int n) { | 14 String threeDigits(int n) { |
| 6 if (n >= 100) return "${n}"; | 15 if (n >= 100) return "${n}"; |
| 7 if (n > 10) return "0${n}"; | 16 if (n > 10) return "0${n}"; |
| 8 return "00${n}"; | 17 return "00${n}"; |
| 9 } | 18 } |
| 10 | 19 |
| 11 String twoDigits(int n) { | 20 String twoDigits(int n) { |
| 12 if (n >= 10) return "${n}"; | 21 if (n >= 10) return "${n}"; |
| 13 return "0${n}"; | 22 return "0${n}"; |
| 14 } | 23 } |
| OLD | NEW |