Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / December 2004

Tip: Looking for answers? Try searching our database.

Output with: Value.formatNumber(double, n) ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Markus Komosinski - 29 Nov 2004 17:22 GMT
Hi!

I have a little problem with the source code of J#.

I would like to have a formated output of a var (e.g. 'sum') in a text box.

In J++ I have to import

       com.ms.wfc.util.*;

to print this output in a text box

       double sum = x + y;
       outputEdit.setText(Value.formatNumber(sum, 2));

What have I to do in J#, or what is to do to have the korrekt output?

Please help!

Regards,
Markus Komosinski
Lars-Inge T?nnessen [VJ# MVP] - 30 Nov 2004 22:37 GMT
Hi Markus,

Here is one example I have made for you. This will compile and run in both
Sun Java and J#.net.

public class test
{
   public test()
   {
       float a = 2.456335f;
       float b = 3.167745f;
       float sum = a + b;
       String format = ".00";    // The format you want.

       java.text.DecimalFormat f = new java.text.DecimalFormat( format );
       String outp = f.format( sum );  // The formatted result.

       // Textbox GUI
       java.awt.Frame fme = new java.awt.Frame();
       java.awt.Dialog dia = new java.awt.Dialog(fme);
       dia.setModal(true);
       dia.setSize(100,75);
       dia.setTitle("hello");

       // Add the result to a textbox/textfield.
       dia.add(new java.awt.TextField(""+outp));
       dia.setVisible(true);

       // Show the TextBox.
       dia.show();
     }

       public static void main(String[] arg)
       {
           new test();
       }
}

Regards,
Lars-Inge T?nnessen
www.larsinge.com
Markus Komosinski - 01 Dec 2004 20:26 GMT
Hi Lars,

thanks for your help.
I've tested your solution, and ... it works!!!

So, I'm a newbie in J#, could you explain me the following lines (please!):

>         String format = ".00";    // The format you want.
[here you define the output format, I get it]

>         java.text.DecimalFormat f = new java.text.DecimalFormat( format );
[what are you doing in this line? please explain me this line! do you add a
new object out of the variable format, and call it f?]

>         String outp = f.format( sum );  // The formatted result.
[in this line I think you convert the formatted sum to an (output string)
variable, called outp, but what means f.format?]

Thanks for your help so far.

Regards,
Markus Komosinski

"Lars-Inge Tønnessen [VJ# MVP]" <http://emailme.larsinge.com> schrieb im
Newsbeitrag news:uvCgE1y1EHA.2540@TK2MSFTNGP09.phx.gbl...

> Hi Markus,
>
[quoted text clipped - 37 lines]
> Lars-Inge Tønnessen
> www.larsinge.com

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.