String Format Help

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.


I need to format a string that comes like this:

12.25486

into

12.25

in vb there is format(string,"##.##") but there's nothing like this in PB...

HELP !!!
:)

--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

look here:
http://www.reelmediaproductions.com/pb/ ... unklib.zip

-------------------------------
http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.

Your tip has been of great help...

But unfortunatly it does not function properly with float numbers :cry:

--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

try:

Code: Select all

Left(StrF(12.25486), 5)
--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.

It works (kind of) !!!
I was wrongly passing the value into the function....


--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

or to deal with other numbers and crop them to 2 decimal places:

Code: Select all

num.f = 12.25486
Debug StrF((Round((num * 100), 1)) / 100)
--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.

Try this...

you'll see what i mean:
7000 € isn't much... i guess my app will go far way pass 7000 in a few months... :cry:

num.f = 7311.25486
Debug StrF((Round((num * 100), 1)) / 100)



--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...
Post Reply