https://github.com/naddiseo/dart-sprintf
Dart implementation of sprintf
https://github.com/naddiseo/dart-sprintf
dart sprintf
Last synced: about 1 month ago
JSON representation
Dart implementation of sprintf
- Host: GitHub
- URL: https://github.com/naddiseo/dart-sprintf
- Owner: Naddiseo
- License: bsd-2-clause
- Created: 2012-09-25T04:59:18.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T05:12:21.000Z (over 3 years ago)
- Last Synced: 2025-10-23T08:34:10.809Z (5 months ago)
- Topics: dart, sprintf
- Language: Dart
- Size: 150 KB
- Stars: 89
- Watchers: 3
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# dart-sprintf
Dart implementation of sprintf.
[](https://travis-ci.org/Naddiseo/dart-sprintf/)
## ChangeLog
[ChangeLog.md](CHANGELOG.md)
## Getting Started
Add the following to your **pubspec.yaml**:
```
dependencies:
sprintf: "^7.0.0"
```
then run **pub install**.
Next, import dart-sprintf:
```
import 'package:sprintf/sprintf.dart';
```
### Example
```
import 'package:sprintf/sprintf.dart';
void main() {
print(sprintf("%04i", [-42]));
print(sprintf("%s %s", ["Hello", "World"]));
print(sprintf("%#04x", [10]));
}
```
```
-042
Hello World
0x0a
```
## Limitations
- Negative numbers are wrapped as 64bit ints when formatted as hex or octal.
Differences to C's printf
- When using fixed point printing of numbers with large exponents, C introduces errors after 20 decimal places. Dart-printf will just print 0s.