IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#57302 - 11/11/19 05:12 PM Format currency and strip leading zeroes
jamescms Offline
OL Newbie

Registered: 11/11/19
Posts: 3
I'm having trouble formatting a currency field and at the same time stripping the leading zeroes. I'm new here and to Planet Press so I'm sure someone could point me to another post where this has been handled. Thank you!

Top
#57303 - 11/11/19 05:51 PM Re: Format currency and strip leading zeroes [Re: jamescms]
jamescms Offline
OL Newbie

Registered: 11/11/19
Posts: 3
Did I mention I'm willing to pay $$$ for answers.

Top
#57304 - 11/12/19 04:47 PM Re: Format currency and strip leading zeroes [Re: jamescms]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
No need to pay.

If you have a true currency field, leading zeroes will be ignored. I suspect you have a string.

In which case, I'd ask you to share what piece of code/which object you are experiencing this with and I'd be glad to help.

Presuming that you're using a common plugin in the Design tool such as Data Selection or Text object, to remove leading zeroes that you're extracting, you could do best by making the following the content of your data selection or variable used:
Code:
=curtostr(strtocur(<data selection>))

By converting to data type currency and then back to string like this, you automatically ensure that the final string is without leading zeroes and with 2 decimal places.

NB: Replace <data selection> above with your current selection or right-click and choose 'select data location', removing my arrow brackets.

Any questions, let me know.

Regards,

James.

Top
#57321 - 11/22/19 01:03 PM Re: Format currency and strip leading zeroes [Re: jim3108]
Italo Ximenes Offline
OL Newbie

Registered: 11/21/19
Posts: 2
Loc: Brasilia, Brasil
I was able to do a function that way.

1. Create a function that stores the value of the data selection.
2.If the value has a fixed size, remove the part that represents the centennial and thousand position.
3. perform the conversion process using 'strtofloat' and 'floattostr'.
4. Verify that the value in the decimal part or the thousand part has been stripped of all zeros and kept the entire part.
5. Follow the code.

function @removeZero(): string
define (&value, string, '0000001.025.48')
define (&initial, integer, 0)
define (&new, string, floattostr (strtofloat (&value)))
define (&hundred, string, left (right (&value, 5), 3))
define (&thousands, string, floattostr (strtofloat (left (&value, 8))))
define (&ten, string, right (&new, 2))

&initial: = length (floattostr (strtofloat (&value)))

if (&initial < 6)
if (length (floattostr (strtofloat(&hundred))) = 2)
&hundred: = floattostr(strtofloat(&hundred))
&new: = &hundred + ',' + &tens
else
&new: = &hundred + ',' + &tens
endif ()
else
&new: = &thousands + '.' + &hundred + ',' + &tens
endif ()

&result: = &new
endfunction ()

Top
#57345 - 12/11/19 05:00 PM Re: Format currency and strip leading zeroes [Re: Italo Ximenes]
jamescms Offline
OL Newbie

Registered: 11/11/19
Posts: 3
sorry for the late response back but i really appreciate the response. It helped a bunch!!!!

k2

Top