Hi I am having a horrible time with a decimal point problem.
I need all numerical values to be converted to a positive integer.
(i.e. for "19.99" to be converted to "1999")

I need to find a script that will check a numerical value to see if a decimal point is present, and if it is, then to remove it.
Else if no decimal point is originally present then to append "00" to the end of the numerical value.

Our shopping cart uses decimal points but the payment gateway doesnt. Items dont always contain a decimal point in the price, Some items may be set with the price 1.25 this needs to be converted to 125, but another price may be 23 for example & this needs to be converted to 2300.

I am not a programmer so this is just to explain what I need, something like...

Dim HSBCPrice
HSBCPrice = ItemTotal

If HSBCPrice contains "." Then remove "."
else

HSBCPrice = HSBCPrice * 100

Please help if you can, as I cant find a script to do this anywhere...


Warm Regards,
Joseph
www.CharitiesOnline.co.uk

Recommended Answers

All 3 Replies

so you need to get the price into cents?

you dont need to get rid of the decimal point just multiply it by 100

<% price = 19.99 %>
<% price = price *100 %>
<%= price %>
gives 1999


<% price = 12 %>
<% price = price *100 %>
<%= price %>
gives 1200

oops...wrong thread...too fast with the mouse

Sorry about my previous post....don't know what happened.

Another method for removing characters from strings is "replace".

Ex: Replace("19.99", ".", "")
(returns "1999")

Of course, in this case it won't work because of the integers.
But another solution could be

if instr(variable_name, ".") > 0 then
replace(variable_name, ".", "")
else
variable_name * 100
end if
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.