Format a string and strip the end...

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi all, I have the format(cdbl(something.text), "f") on some of my labels, these labels display answers from math equations, how do I trim the end if it is a zero? I have looked on-line but still confused to the setup.

Example: 10.4 instead of 10.40, but leave a value that is 10.41 with two decimal places when needed.

Thanks in advance...
 
Last edited:

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Yeah I tried that style, and for some reason it will let the number run when it is like1.03333333333333. Not sure why it is doing this??? I have also tried "{0:0.##}", there is a way to trim.endwith("0") right, I tried to built this into sub - (maybe not the right place-maybe put it with the calculation directly - humm I will try it)

just not sure if I set it up right, this is a boolean type so I was using the IF..endIF statement to change it to "{0:0.#}", just couldn't get the syntax right.

VB.NET:
Label9.Text = Format("{0:0.0#}", (CDbl(witbox1.Text) * CDbl(AdeDos.Text)))
Thanks for taking a look...
 
Last edited:

Robert_Zenz

Well-known member
Joined
Jun 3, 2008
Messages
503
Location
Vienna, Austria
Programming Experience
3-5
That's odd, 'cause it's working for me.

The only reason I could think of is that there's maybe something wrong with localization. F.e. I have a german profile, text like "1.0333333" would show me (in american format) 1,0333333.0, while "1,03333333" shows me 1.03 .

Bobby
 

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
ok, it works for anything that does not have a reocuring digit (forgot what they call that - .3333333333333333...)
 

Robert_Zenz

Well-known member
Joined
Jun 3, 2008
Messages
503
Location
Vienna, Austria
Programming Experience
3-5
You mean periodic numbers.
Mh...that could be...maybe you can cut this if you use Substring before formatting. I mean, getting the result into a string, look how long it is, and if it is too long then cut it with substring.

Bobby
 

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Accually I got it working by placing the format style at the end - format((x) "0.0#"), instead of the beginning, which is weird as all the examples I had seen placed it at the beginning, like I showed in an earlier post.

Glad it is working none the less...Thank you for your time Bobby.
 
Top Bottom