For Programmers: Free Programming Magazines  


Home > Archive > Clipper > March 2005 > Gavascript Parseint()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Gavascript Parseint()
Steel

2005-03-29, 8:55 am

Hi at all,
please can you translate the javascript Parseint() function to a clipper
language

In particular How can I translate to Clipper 5.3:

wDay = parseInt(wDay, 10)
if (isNaN(wDay))
wDay = 0

Steel


Richard Bos

2005-03-29, 3:55 pm

"Steel" <SteelNOSPAM@hotmail.com> wrote:

> please can you translate the javascript Parseint() function to a clipper
> language


Not in the general case; that is, not in any bases apart from decimal.

> wDay = parseInt(wDay, 10)
> if (isNaN(wDay))
> wDay = 0


This snippet, though, parses only decimal numbers anyway, and the
Clipper val() returns 0 as its error value in the first place, so you
can simply do

day=val(day)

Do note that this does parse "123aaa" as 123; and does parse "123.45" as
123.45. If you only want integers, you can always ask for int(val(day)).
Unfortunately, if you want to make sure there are no non-digits in the
string you'll have to make sure of this yourself; if you get the string
from user input, a @get with a picture consisting of 9s or #s will not
let the user enter non-numeric data in the first place.

Richard
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com