Skip to content

Commit 0f11037

Browse files
committed
---
yaml --- r: 14406 b: refs/heads/try c: 6527fc3 h: refs/heads/master v: v3
1 parent 42dbf39 commit 0f11037

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 910a32c7c777296be0992bf0d6f2d66261c407d6
5+
refs/heads/try: 6527fc392536b0f72f652e85a9950ede9f363494
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/float.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
5252
let trunc = num as uint;
5353
let frac = num - (trunc as float);
5454
accum += uint::str(trunc);
55-
if frac < epsilon || digits == 0u { ret accum; }
55+
if (frac < epsilon && !exact) || digits == 0u { ret accum; }
5656
accum += ".";
5757
let i = digits;
5858
let epsilon = 1. / pow_uint_to_uint_as_float(10u, i);
@@ -83,6 +83,12 @@ fn to_str_exact(num: float, digits: uint) -> str {
8383
to_str_common(num, digits, true)
8484
}
8585

86+
#[test]
87+
fn test_to_str_exact_do_decimal() {
88+
let s = to_str_exact(5.0, 4u);
89+
assert s == "5.0000";
90+
}
91+
8692
/*
8793
Function: to_str
8894

branches/try/src/test/run-pass/syntax-extension-fmt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ fn part4() {
136136
test(#fmt["%.5t", 3u], "00011");
137137
test(#fmt["%.5c", 'A'], "A");
138138
test(#fmt["%.5f", 5.82], "5.82000");
139+
test(#fmt["%.5f", 5.0], "5.00000");
139140
// Bool precision. I'm not sure if it's good or bad to have bool
140141
// conversions support precision - it's not standard printf so we
141142
// can do whatever. For now I'm making it behave the same as string

0 commit comments

Comments
 (0)