FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 1156 : nf() with a float and right decimal of 0 doesn't work
Last modified: 2009-02-26 19:47
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
FIXED -
Pr
i
ority:
P2
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
Eric F.
Assigned To:
REAS
Attachment
Type
Created
Size
Actions
sample code
patch
2009-02-07 19:40
106 bytes
Description
: Opened: 2009-02-07 19:35
nf() float formatting with 0 decimal places doesn't work - unless the float happens to
be a whole number.
Additional Comment
#1 From Eric F. 2009-02-07 19:38
[code]
// this works
println( nf(1.0,1,0) );
//this doesn't
println( nf(1.1,1,0) );
[/code]
Additional Comment
#2 From Eric F. 2009-02-07 19:40
edit
]
sample code
Additional Comment
#3 From fry 2009-02-08 06:21
use floor() or int() if you want to remove decimals.
when zero is used in either the left or right position, that indicates that
no changes should occur.
(switching this to a reference bug so it can be noted as such.)
Additional Comment
#4 From Eric F. 2009-02-08 09:22
in that case, a value of 1.0 should display as "1.0" - but it doesn't, it displays as "1"
- the decimal is truncated. either way behavior is inconsistent.
(In reply to
comment #3
)
>
>
>
> Additional
Comment #3
From
>
> fry
> 2009-02-08 06:21
>
> <!--
> addReplyLink(3); //-->[reply]
>
>
>
>
> use floor() or int() if you want to remove decimals.
>
> when zero is used in either the left or right position, that indicates that
> no changes should occur.
>
> (switching this to a reference bug so it can be noted as such.)
>
>
(In reply to
comment #3
)
>
>
>
> Additional
Comment #3
From
>
> fry
> 2009-02-08 06:21
>
> <!--
> addReplyLink(3); //-->[reply]
>
>
>
>
> use floor() or int() if you want to remove decimals.
>
> when zero is used in either the left or right position, that indicates that
> no changes should occur.
>
> (switching this to a reference bug so it can be noted as such.)
>
>
Additional Comment
#5 From fry 2009-02-08 10:08
again, use floor(), or int(), or even round() or ceil() for that matter.
nf() is not for removing decimals.
it's not inconsistent, it's just that using 0 on the right-hand side is
almost totally pointless, but it's there for symmetry with the left-hand
side, where it's more useful.
Additional Comment
#6 From Eric F. 2009-02-08 10:24
ok thanks. i guess i'm confused as to why nf() would call changing "1.0" to "1", no
change. the string returned is changed in one case and not in the other. compare,
e.g., to the string returned by println(). seems inefficient to have to use
nf(round(x),1,0), i thought the point of the NumberFormat command is for formatting
numbers consistently. but i see what you're saying, thanks for the response.
Additional Comment
#7 From REAS 2009-02-26 19:47
I've updated the nf() reference to clarify.