|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
format number againi need to write double number to a fixed lengh, es.: 3 -> 3.00 3.3 -> 3.30 i use format Format(Text, "00.00") but it isnt ezactly what i need, this returns: text=3.3 format-> 03.30 i need <blank>3.30 do you know what have i to write??? i tried Format(Text, "##.0") but it doesnt work thanks carlo thanks carlo "Carlo" <carletto.m@NOSPAMgmail.com> wrote in message Use....news:%23i6onU0zFHA.3856@tk2msftngp13.phx.gbl... > Hi > i need to write double number to a fixed lengh, es.: > > 3 -> 3.00 > 3.3 -> 3.30 > > i use format > Format(Text, "00.00") Format$(YourNumber, "0.00") That ensures a leading 0 and 2 decimal places. 3 will be 3.00 point 3 will be 0.30 9993.3 will be 9993.30 etc. -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups.. thanks a lot
but this isnt what i need i solve the problem in this way: sRiga = sRiga & String(7 - Len(Format(.Text, "0.00")), " ") & Format(.Text, "0.00") & vbTab thanks carlo Show quoteHide quote "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> ha scritto nel messaggio news:OZn1uf0zFHA.4032@TK2MSFTNGP15.phx.gbl... > "Carlo" <carletto.m@NOSPAMgmail.com> wrote in message > news:%23i6onU0zFHA.3856@tk2msftngp13.phx.gbl... >> Hi >> i need to write double number to a fixed lengh, es.: >> >> 3 -> 3.00 >> 3.3 -> 3.30 >> >> i use format >> Format(Text, "00.00") > > Use.... > > Format$(YourNumber, "0.00") > > That ensures a leading 0 and 2 decimal places. > > 3 will be 3.00 > > point 3 will be 0.30 > > 9993.3 will be 9993.30 > > etc. > > > > > -- > Ken Halter - MS-MVP-VB - http://www.vbsight.com > DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > Please keep all discussions in the groups.. > "Carlo" <carletto.m@NOSPAMgmail.com> wrote in message You are trying to right-justify the value in a 7-character field? Maybenews:etEJ%23l0zFHA.736@tk2msftngp13.phx.gbl > thanks a lot > but this isnt what i need > > i solve the problem in this way: > sRiga = sRiga & String(7 - Len(Format(.Text, "0.00")), " ") & > Format(.Text, "0.00") & vbTab something like sRiga=Format$("###0.00",CSng(.Text)) & vbTab or sRiga=Right$(Space$(4) & Format$("0.00",CSng(.Text)),7) & vbTab Both avoid the implicit string->number conversion and doing the same format call twice. -- Reply to the group so all can participate VB.Net: "Fool me once..." > > thanks a lot field? Maybe> > but this isnt what i need > > > > i solve the problem in this way: > > sRiga = sRiga & String(7 - Len(Format(.Text, "0.00")), " ") & > > Format(.Text, "0.00") & vbTab > > You are trying to right-justify the value in a 7-character > something like Hmm! Funny syntax on your Format statements there Bob... did you> > sRiga=Format$("###0.00",CSng(.Text)) & vbTab > > or > > sRiga=Right$(Space$(4) & Format$("0.00",CSng(.Text)),7) & vbTab > > Both avoid the implicit string->number conversion and doing the same format > call twice. forget to drink your coffee this morning?<g> Also, that first statement won't work (even after reversing the arguments in the Format statement); multiple # signs do not hold multiple places. Since you have a zero in front of the decimal point, the three # signs you show will not have any effect (leave them off and you will get the same output). The second statement you show will work fine though (after reversing the Format function's arguments of course), although you omitted the concatenation of sRiga onto the front of the statement. Lack of coffee, right? Another coding possibility is the following sRiga = sRiga & Format$(Format$(3.3, "0.00"), "@@@@@@@") & vbTab True, this uses the Format function twice, but each usage is different. Rick "Rick Rothstein [MVP - Visual Basic]"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote in message news:eYYX8I1zFHA.3336@TK2MSFTNGP12.phx.gbl <cut>> Hmm! Funny syntax on your Format statements there Bob... did you LOL> forget to drink your coffee this morning?<g> I don't drink coffee; perhaps I should start! > Also, that first statement won't work (even after reversing the I thought I remembered the # as being leading 0 or space... I don't> arguments in the Format statement); multiple # signs do not hold > multiple places. Since you have a zero in front of the decimal > point, the three # signs you show will not have any effect (leave > them off and you will get the same output). actually use the Format function very much so these little details tend to escape the brain over time. > The second statement No, just didn't read the OP carefully enough> you show will work fine though (after reversing the Format > function's arguments of course), although you omitted the > concatenation of sRiga onto the front of the statement. Lack of > coffee, right? > Another coding possibility is the following That doesn't bug me nearly as much as the code that did exactly the same> > sRiga = sRiga & Format$(Format$(3.3, "0.00"), "@@@@@@@") & vbTab > > True, this uses the Format function twice, but each usage is > different. formatting twice. I still prefer not using Format if I can do it another way just as easily. Not sure why I dislike it like I do but I do try to avoid it. -- Reply to the group so all can participate VB.Net: "Fool me once..." ....
> > You are trying to right-justify the value in a 7-character [sic, modified to remove syntax error and leave only the format]> field? Maybe > > something like > > Format$(CSng(.Text), "###0.00") Which is why I've always thought Format$() either needed rules similar.... > Also, that ... statement won't work (even after reversing the > arguments in the Format statement); multiple # signs do not hold > multiple places. ... to Fortran FORMAT statements or another placekeeper for precisely the purpose Bob wanted # to serve. Actually, I never understood why # wasn't defined in that manner... > i need to write double number to a fixed lengh, es.: The 0 and # characters are place holders for numbers... the 0> > 3 -> 3.00 > 3.3 -> 3.30 > > i use format > Format(Text, "00.00") > but it isnt ezactly what i need, this returns: > text=3.3 format-> 03.30 i need <blank>3.30 > do you know what have i to write??? > i tried Format(Text, "##.0") but it doesnt work forces a zero to be outputted if there is no digit in the specified place and the # outputs the empty string ("") if no digit exists. Now, on to your question. I'm afraid it isn't entirely clear what you want in the general situation. For example, can you have a number whose integer part is 2 or more digits (such as 12.34)? If so, what did you want to output for this situation? In other words, are you always looking to output a leading blank space? Or are your numbers confined to a maximum of two digits in the integer part and you want the blank space only when a single digit appears in the integer portion of the number? Or something else I haven't thought of? Also, what did you want outputted if the number has no integer portion (such as .456)... a leading blank followed by a zero or just two leading blanks? Rick
excel versions in Vb 6
Application error "Permission Denied" only under WinXP-SP2 Is there a more elegant way to do this? Update Workstations with new executable Compile, Save, Exit, ReStart, big trouble Problem connecting to remote MySQL DB from VB6 Dependency walker and custom ocx. Lexical analysis How many ORs can you have in ADODB INTODUCTION TO VISUAL BASICS |
|||||||||||||||||||||||