|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
__________________
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 |
|
#3
|
|||
|
|||
|
try using format function like this...
label1.caption = format(text1.text,"####.##") |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
Thanks guys!
I had to change the decimal symbol in the control panel to get it working properly... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > How to format number 1 to 1.00 and 1.5 to 1.50 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|