Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2003, 02:06 PM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
How to format number 1 to 1.00 and 1.5 to 1.50

Hello!
I guess this is an easy one but I haven't found the solution yet. I have a textbox for input. The input can be given as an integer or with decimals. I need a function that changes the input to decimal. If the input is given as 1 I would like it to be changed to 1.00 and if it is given as 1.5 I would like the function to add one zero to the end 1.50.

Is it possible to keep three decimals if the input is given with three decimals? 1.234 => 1.234

I hope you understand what I'm trying explain.

Regards, Knappe

Reply With Quote
  #2  
Old November 3rd, 2003, 03:50 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,176 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 42 m 4 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
I would suggest reading


HERE
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old November 3rd, 2003, 04:01 PM
crackerweb crackerweb is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 786 crackerweb User rank is Private First Class (20 - 50 Reputation Level)crackerweb User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 18 h 16 m
Reputation Power: 6
try using format function like this...
label1.caption = format(text1.text,"####.##")

Reply With Quote
  #4  
Old November 3rd, 2003, 05:45 PM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
My function looks like this:

Wq_u.Text = Format(Wq_u.Text, "#.##")

If I give something else then an integer as input the value in the textbox changes to
36708,

What am I doing wrong?

Reply With Quote
  #5  
Old November 3rd, 2003, 10:34 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
I recommend u to use Named Formats in the format function..
Visual Basic provides several standard formats to use with the Format function. Instead of designating symbols in the format argument, you specify these formats by name in the format argument of the Format function. Always enclose the format name in double quotation marks ("").

The following table lists the format names you can use.

Named format Description
General Number Displays number with no thousand separator.
Currency Displays number with thousand separator, if appropriate; display two digits to the right of the decimal separator. Output is based on user's system settings.
Fixed Displays at least one digit to the left and two digits to the right of the decimal separator.
Standard Displays number with thousand separator, at least one digit to the left and two digits to the righseparator.
Percent Multiplies the value by 100 with a percent sign at the end.
Scientific Uses standard scientific notation.
General Date Shows date and time if expression contains both. If expression is only a date or a time, the missing information is not displayed. Date display is determined by user's system settings.
Long Date Uses the Long Date format specified
by user's system settings.

Medium Date Uses the dd-mmm-yy format (for example, 03-Apr-93). Date display is determined by user's system settings.
Short Date Uses the Short Date format specified by user's system settings.
Long Time Displays a time using user's system's long-time format; includes hours, minutes, seconds.
Medium Time Shows the hour, minute, and "AM" or "PM" using the "hh:mm AM/PM" format.
Short Time Shows the hour and minute using the hh:mm format.
Yes/No Any nonzero numeric value (usually ¨C1) is Yes. Zero is No.
True/False Any nonzero numeric value (usually ¨C1) is True. Zero is False.
On/Off Any nonzero numeric value (usually ¨C1) is On. Zero is Off.


The Format function supports many other special characters, such as the percentage placeholder and exponents.

For More Information See "Format Function" in the Language Reference

It came from
http://msdn.microsoft.com/library/d...sdatestimes.asp

Reply With Quote
  #6  
Old November 4th, 2003, 12:26 PM
Knappe Knappe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Knappe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanks guys!
I had to change the decimal symbol in the control panel to get it working properly...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to format number 1 to 1.00 and 1.5 to 1.50


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway