NetTalk Central

Author Topic: Help! How to accept a COMMA and/or a PERIOD in numeric fields?  (Read 4620 times)

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« on: February 02, 2012, 06:25:42 AM »
Hi Bruce,

I have changed my Number Fields to String Fields and use a numeric picture.
We have customers that use a COMMA as decimal, for example: 1,25
But we have also customers that use a PERIOD as decimal, for example 1.25

At this moment I have a string field with picture @N5`2B (comma as decimal separator), but this only accepts a COMMA.
When I use a PERIOD, it's going wrong.

So the question is:
How do I accept on a string field the pictures @N5`2B (comma as decimal separator) AND @N5.2B (period as decimal separator)?

I hope there is a solution!

Best regards
Jeffrey

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #1 on: February 02, 2012, 10:39:04 AM »
I would leave it as a string without a format. Then parse out the comma and period in the client side tab's server code.
Set both the variable and its session value.
Real programmers use copy con newapp.exe

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #2 on: February 02, 2012, 04:28:40 PM »
The other option is to set the Picture to a session value. If your users login you could store this as part of their setup (I do this for date formats). Alternatively you could try to detect what country the user is logging in from via their IP address and set the format accordingly.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #3 on: February 02, 2012, 10:42:55 PM »
this is a suitably interesting question that it's worthy of an interesting answer.

Firstly, we need to consider ways numbers can be typed in; and then we'll deal with your special case.

nnn-nn, nn-nn, n-nn, n, nn, nnn nn-n
are all fairly unambiguous. the separator, be it , or . is the decimal indicator.

if the number can be more than 999.99 though you get a complication. Because then you could have
n,nnn.nn or n.nnn,nn so the algorithm for parsing the number needs to be more complex.
fortunately in your case the number is @n5.2 so that's not a consideration for now.

Secondly we want to embed code in one place, but which works for both the immediate field, and also when the user clicks on Save. That means the ValidateValue::Fieldname embed.

the following code translates a , into a .

num   string(15)  
x  long



 If p_web.RequestAjax = 1 and p_web.ifExistsValue('Value')
    p_web.SetValue('ALI:Roman',p_web.GetValue('Value'))
  end          
  num = p_web.GetValue('ALI:Roman')
  x = instring(',',num,1,1)
  if x > 0
    num[ x ] = '.'
  end  
  ali:roman = num


The first IF takes care of the dynamic case, after that the Ali:Roman field is "re-parsed" from the original "value".

Any questions?



« Last Edit: February 03, 2012, 12:16:57 AM by Bruce »

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #4 on: February 02, 2012, 11:51:24 PM »
Thank you guys!

Bruce, you have made it even more simple.
Please look at the screenshot.
This works just out of the box!  ;)

So now I can use a COMMA and/or a PERIOD as decimal separator.
After accepting the field, always a PERIOD is shown as decimal separator, but that's ok for me.

Best regards
Jeffrey


[attachment deleted by admin]

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #5 on: February 03, 2012, 07:22:59 AM »
Jeffrey,
Did that fix it without the embed code???
Brilliant!

chris
Real programmers use copy con newapp.exe

Jeffrey Kuijt

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • Email
Re: Help! How to accept a COMMA and/or a PERIOD in numeric fields?
« Reply #6 on: February 03, 2012, 07:30:15 AM »
Hi Chris,

Yes, it did!  ;D

Best regards
Jeffrey