Jul 20, 2008

Need Help With Decimalformat - Showing too many/not enough decimals

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Need Help With Decimalformat - Showing too many/not enough decimals

beeseven
Right now I have this:
CODE
DecimalFormat form = new DecimalFormat("0.00");
form.toPattern();
form.format(tot);

The Java API said that 0 would be a digit that you didn't want ignored (ie an extra zero), but it's only showing the first 0 after the decimal. This is a monetary value so I have to have exactly 2. Also sometimes it weirds out and goes from 0.05 to 0.0600...002 or from 0.09 to 0.0999..., so I need it to round to those 2 decimals, too.

As for the DecimalFormat I've tried "#.##", "0.#0", "#.#0", and "0.##" but those didn't work, either.

Reply

cse-icons
hi beeseven,

Your code seems fine. I tried it out and the results came as expected i.e, with 2 decimal places(either rounded of if more decimal places exist or 0 appended if decimal places not sufficient).
you also do not need to call form.toPattern() method. but that does not make a difference anyway.

what is the data type of 'tot' that you are passing to format() method. That might be affecting the output.

btw fyi I tried it out on JDK 1.4.2, if the issue is still not solved, could you post more of the code.

Also check out if you are using the DecimalFormat class from the java.text package only. It might be the a class with the same name existing in some other package in your classpath has been accidentally imported. This happens in case you are using IDE and you have chosen the import from a drop down or something automatically.

Cheers.

Reply

beeseven
I got some help with it in my class: DecimalFormat returns a string but doesn't change the variable, so I had to say
CODE
label.setText("$"+form.format(tot));

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : decimalformat, showing, decimals

  1. Site Help [resolved]
    Showing good on one site but but here on trap17 (6)
  2. Html Page Not Showing Up In Firefox
    (1)
    Hi, I've tried to make a webpage in HTML using the frameset tag. Here is the code of the
    webpage Sai's Makeshift Wiki And it's not displaying in Firefox. (I
    mean is shows a blank page) It will show up in safari (I'm a mac user), all pages individually
    work on firefox, just not the above page. Any ideas as to why? Thanks....
  3. Porn Ads Showing On My Website O_o
    (13)
    ok.. so i have a thing to look exesevely at my website.. & the hell.. like 4 times already a random
    porn add shows up a hot babe is waiting for you, or something like that. i dont know whats wrong,
    if something hacked my website, and added that, or if its my computer, with some nasty virus again
    o.o anywho, yea, i tried doing some research and nothing shows up!!!! help?....
  4. Treating .csv Files As Database Data
    Showing .CSV data on a web page (2)
    I use a nice program (which I helped to beta test) called ' Simfatic Forms ' to generate
    forms on web pages. The only problem is that it does not (yet) support MySQL databases, it saves the
    form data as a .CSV file. Now I was wondering if you can do the same with a .CSV file as you do
    with a MySQL databse, ie. displaying the data in that file on a web page which adjusts automatically
    as data are added to the file. To clarify: eg. if I make a form to sign a petition online, the data
    are saved to a .CSV file every time someone fills in the form, is it now possibl....
  5. Glitch On This Forum? [resolved]
    Picture not showing up (4)
    Hello, I hope this is the right place to post this, I couldn't find any other place where this
    would fit. Weeks ago, I uploaded a picture to go with my username. Yet I notice it does not show
    up, only when I click my username on the left of the forum, it shows up. I did notice that with
    other users, their picture shows up next to (or underneath) their name. I was wondering why this is
    happening. Thanks. ....
  6. My Site Is Showing Trap17 Activation Page Only [resolved]
    my forum is not showing with www path (2)
    Hello I have requested for the free hosting with my own domain name and everything is in orderbut i
    am having this proble and here goes each time i type www.mysite.com instead of me seeing the home
    page of my site what i will be seeing is the default trap17 page where it will tell the visitor
    welcome to trap17 web hosting this domain is hosted with trap17 i have deleted the page creat my own
    index page but still i am seeing this page now agian each time i type www.mysite.com/yabb.pl that is
    the direct link to my forum script it wont open instead it will tell me can not f....
  7. My Domain Showing Blank Page (not Timeout) On Load [resolved]
    It works through an "anonymous" proxy (6)
    As far as I know this problem has been on me for one, maybe two weeks now. When i try to access my
    site all I get is a completely blank page. The source code also shows a completely blank page. I
    would provide a screenshot, but there's nothing there to see!!!!!!!
    Bear in mind it's not a timeout error, and the title bar, instead of showing the real "page
    title" and favicon, just shows my site's address. This problem is the same in both IE & FF. I
    CAN login to the administration area for my site with /administrator/ on the end, and ....
  8. Shoutbox Not Showing In Netscape Navigator
    What do I do? (3)
    I am running Netscape Navigator 7.0 and for some reason the shoutbox module here at Trap 17
    is not coming up properly. This is what I get The side panel module doesn't appear either in
    the edit/post mode that I am using right now. Me thinks it may have something to do with java
    script. I do have it enabled in preferences/advanced. Can somebody tell me where to go and what to
    do to correct this? ....
  9. Addon Domains. Having Problems?
    My addon domains are not showing in the control panel. (2)
    Hi. I just want to find this out before I submit a support request. It may probably be a global
    problem /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" /> I have an addon domain in my account which is showing fine in my addon
    domains section, however, the emails and subdomains associated with this domain just disappeared. I
    can't add subdomains to the this addon domain either /sad.gif" style="vertical-align:middle"
    emoid=":(" border="0" alt="sad.gif" /> Is this just my account or it's global?....
  10. Phpbb2 Error
    recently showing up (4)
    I tried to install a mod. Did it successfully but didn't like the end result. So I went through
    the install backwards and reverted everything back to how they were. Now I am getting this error.
    QUOTE Warning: Cannot modify header information - headers already sent by (output started at
    /home/damen/public_html/phpBB/language/lang_english/lang_main.php:1034) in
    /home/damen/public_html/phpBB/includes/page_header.php on line 483 Warning: Cannot modify header
    information - headers already sent by (output started at
    /home/damen/public_html/phpBB/language/lang_english....
  11. My Site Is Showing A Forbidden Message, Need Help Now.
    Please help me admins or moderators. (3)
    My site is showing a forbidden message saying i can not get to a certain folder, and i did not
    change permissions or whatever. I am concerned with this, i have thousands of visitors per day and
    i am loosing them for the competition. Please help me with this, as i said, i did not do a thing
    for this to happen.....
  12. My Latest Sigs - Showing Off
    (0)
    my latest 4 sigs.. any comment? doh, the title was supposed to be "my latest sigs"
    but dunno why it didn't show the rest lol sorry xD....
  13. Mediawiki Not Showing
    (2)
    Hi, i've just installed the latest SVN of mediawiki, and it installed just fine, but now the
    wiki wont show up. Only thing I see is "�". Could this be a problem with the advert text?
    Site is located at http://www.pslib.qupis.com/wiki ....
  14. Showing Latest Phpbb Topic On Homepage
    (2)
    hi, sorry if ive posted it in the wrong forum but can anyone help me out, to find a script that wil
    show the latest topics of my forum on the home page? many thanks....
  15. How Do I Remove This External Storage From Showing?
    (0)
    I have been having a peculiar problem. Everytime I boot up the computer, there would be external
    storage in my G: drive. When i click on it, it shows me that this is inaccessible, I can only
    deduce there isn't anything there because other than my printer, I am not using any of the USB
    slots. Is there a way to permanently remove this G: from showing up unless a removable media is
    plugged in. Can any of the gurus tell me how I can solve this problem? This is not a must, but I
    just don't like my computer looking funnily, yeah thats just me.....
  16. Google Earth's New Update
    showing more details (1)
    Google Earth got updated last month and now is showing more pictures than befor Anyway im board plz
    pm me and become one of my freinds or just chat with me and I cant wait to get a hosting server even
    though I have only been here a day lol please send me pm's as I get board very easly lol anywayz
    cya yous all later!! Stay within the topic and do not digress. One discussion per topic ....
  17. How Google Works, Videos Made By Matt Cutts, The Google Software Engineer
    17 high quality videos showing how google works! A master piece (0)
    Yes, the most famous google software engineer, Mat Cutts, the one himself, made a 17 free videos,
    with top quality free information about his opinions of how google works. I do not know about you,
    but i am downloading every video i can, they are free, hosted at the high speed google network,
    which should take a couple of minutes for anyone to download and see, or just click and visit the
    links to see the videos online, the videos quality is good. Mat Cutts, only by himself, as you can
    see on those videos, explains you, his opinions on how he thinks google works, let m....
  18. Remove Unnecessary Decimals With Php?
    (3)
    I have a MySQL DECIMAL field allowing up to 3 decimals to the number. However, many of the numbers
    only have one decimal. An example is 5.2. I want the script to echo ONLY 5.2 and not 5.200. However,
    if the number is 5.211, I want it to echo the whole number, so I can't just use the round()
    function. Is there a way to do this?....
  19. Showing Html In A Webpage
    (0)
    ok well heres the rub, i have an HTML and PHP script i want to put on my website, but this is for a
    tutorial, so i dont want the PHP and HTML script to do what i have it set to do, i want the people
    reading the page to be able to read it.... i tried the HTML pre > /pre > script, but that
    didn't work... any ideals http://www.orderofhogwarts.com/php_includes.php Topic resolved
    in shout box. Closing. ....
  20. Still showing the default index page after FTP upload
    (4)
    Hey, i need a little help. I just got my account. I uploaded the index.html file using an ftp, but
    when i try going on my page, it still shows the default page. How do i fix this?....
  21. Images Not Showing On Addon Domain
    (6)
    Hello everyone! We got the addon domain to work. Wooohoo! But there is one little
    problem... the images aren't showing up. LOL! Anyone know what's wrong? Here is the url
    for a test page I made: http://www.suzyminer.com/test.htm As you can see, there is an X where
    the image should be.....
  22. Showing Numbers Of Mysql Entries In A Database Table
    It should be easy, but I don't know how... (7)
    I have a database, and need to know how to show the numbers of entries. So, if there are 10 entries
    in the selected database table, it will show the number 10 . I'm pretty sure this should be
    easy, but I don't know how to do it. Can someone tell me? /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  23. Showing Numbers With Mysql
    (5)
    I have a int column with numbers, and I want to show only the numbers between 5 and 20 in that
    column. So my list would be like this: CODE 5 7 15 16 I know how to only show numbers that
    are less than 20 or greater than 5, but I can't manage to combine those two (Less than 20 AND
    greater than 5). So I guess it would be something like this: CODE SELECT * FROM `table`
    WHERE `introw` >= 5 && <= 20 How can I do that?....
  24. Showing Off A Signature
    Made by me (2)
    So, I like to draw but to actually sit and take the time to do so, and having to erase all the time
    gets frustrating. So i was looking at guys to draw, and i just was just over drawing. But I had
    photoshop open, so i decided that i'd work with that instead. Now i havent ever used the sketch
    things for drawings, so it was kind of trial and error i guess. I used a mixture of a lot of things
    though, just continuesly duplicating the layers, and putting stuff behind the layers. I should have
    just written down the the steps, but like i said its just trial and error, and it....
  25. Seeking 3 Dimensional Interface
    about window showing (6)
    hey ,do me a favor that i am seeking a software now. there has been a software called MaDotate which
    can show a 3D window but not very ripe till now /sad.gif' border='0' style='vertical-align:middle'
    alt='sad.gif' /> like vista below...do you know some software which can simulate the style when a
    window showing.often we can use xpstyle or windowbinds to beautify or theme.although those software
    is run much memory,i do wanna have a try /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> Topic title is very important. Make it count! ....
  26. Website Changes Not Showing Up
    FTP server isn't updating my site (2)
    When I upload to 69.50.188.18, it uploads there but it doesnt change my site. Is that a backup
    server or something because my site isn't getting updated. I can connect to there though. I
    tried connecting to spudguns.trap17.com and ftp.spudguns.trap17.com . Neither of them worked.....
  27. Ie Not Showing Transparent Png
    (6)
    First, I'm aware that IE does have some type of issue displaying transparent PNG's (though
    from what I've read, it just confuses me more than helps me understand). My site (a hurricane
    tracking site) has (or will soon) several hundred images. What I'm trying to do is have two base
    images, black and white, and color. Then I have storm tracks drawn on the transparent PNG. Now, both
    of these images (either the bw or color) and the PNG are displayed with the PNG being offset the
    height of the base image. The reason I'm doing this is because the user has ....
  28. Escape Characters Showing In Thread Title
    in forums list but not in bottom section (2)
    Hello, I noticed today that escape characters are showing up in the "last post info" box of a
    forum in the main page: It seems to display correctly in all the other places though. The list
    of posts at the bottom of the page displays it correctly: Similarly, the title looks fine in the
    "topic title" box in the subforum: http://www.trap17.com/forums/dating-advice-f194.html Thank you
    for your attention, it's not a big deal but I thought I would be neighborly and point it out.
    Thanx....
  29. Some Stuff Not Showing
    in phpnuke site (7)
    hey, im having a problem with my site.. the boxes on the left are showing but the ones on the right
    are not.. they are all activated, but still not showing? any idea why? or how i can fix it.
    http://berkolli.trap17.com ....
  30. Not Showing My Email Address
    but sometimes it does. (6)
    In my forum control panel I selected the option to hide my email address from other members.
    However, I have noticed that in all hosting requests, upgrades etc my email is there for everyone to
    see. This of course is the same for everyone requesting hosting. I understand it is necessary for
    the admins to see the email addresses to process the applications, but perhaps you could make it so
    only moderators and admins can see these posts? That way those of us that want to keep our email
    addresses hidden are not 'exposed' as such. I doesn't bother me that much....

    1. Looking for decimalformat, showing, decimals

Searching Video's for decimalformat, showing, decimals
Similar
Site Help
[resolved] -
Showing good
on one site
but but here
on trap17
Html Page
Not Showing
Up In
Firefox
Porn Ads
Showing On
My Website
O_o
Treating
.csv Files
As Database
Data -
Showing .CSV
data on a
web page
Glitch On
This Forum?
[resolved] -
Picture not
showing up
My Site Is
Showing
Trap17
Activation
Page Only
[resolved] -
my forum is
not showing
with www
path
My Domain
Showing
Blank Page
(not
Timeout) On
Load
[resolved] -
It works
through an
"anonymo
us"
proxy
Shoutbox Not
Showing In
Netscape
Navigator -
What do I
do?
Addon
Domains.
Having
Problems? -
My addon
domains are
not showing
in the
control
panel.
Phpbb2 Error
- recently
showing up
My Site Is
Showing A
Forbidden
Message,
Need Help
Now. -
Please help
me admins or
moderators.
My Latest
Sigs -
Showing Off
Mediawiki
Not Showing
Showing
Latest Phpbb
Topic On
Homepage
How Do I
Remove This
External
Storage From
Showing?
Google
Earth's
New Update -
showing more
details
How Google
Works,
Videos Made
By Matt
Cutts, The
Google
Software
Engineer -
17 high
quality
videos
showing how
google
works! A
master
piece
Remove
Unnecessary
Decimals
With Php?
Showing Html
In A Webpage
Still
showing the
default
index page
after FTP
upload
Images Not
Showing On
Addon Domain
Showing
Numbers Of
Mysql
Entries In A
Database
Table - It
should be
easy, but I
don't
know how...
Showing
Numbers With
Mysql
Showing Off
A Signature
- Made by me
Seeking 3
Dimensional
Interface -
about window
showing
Website
Changes Not
Showing Up -
FTP server
isn't
updating my
site
Ie Not
Showing
Transparent
Png
Escape
Characters
Showing In
Thread Title
- in forums
list but not
in bottom
section
Some Stuff
Not Showing
- in phpnuke
site
Not Showing
My Email
Address -
but
sometimes it
does.
advertisement



Need Help With Decimalformat - Showing too many/not enough decimals



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE