Page 1 of 1

Format number

Posted: Sun Sep 23, 2018 7:44 pm
by cbarbal
I have downloaded the DGH trial. I followed the lessons to be able to format a field "### ## 0.00", decimal separator "," and separator of thousands ".". I do not get an error but it does not format it. It can be a limitation of the trial?

Regards,

Carles

Re: Format number

Posted: Mon Sep 24, 2018 1:23 am
by [-hh]
These separators don't work with the usual number format.

I don't use/know DataGrid but here is function that does with every LiveCode field what you want. You have to input your numbers (with comma as decimal separator) and then hit enter to get the field formatted as "thousands.hundreds,decimals".

Code: Select all

-- [by -hh] script for a field with the wanted
-- number format "thousands.hundreds,decimals" 
-- input numbers using "," as decimal separator!

local sc -- the selectedChunk

function myNumberFormat x
  if x > 1000 then
    put (x div 1000) & "." into thsnd
  else put empty into thsnd
  put x mod 1000 into hndrd
  put format("%0.2f",hndrd) into hndrd
  replace "." with "," in hndrd
  put thsnd & hndrd into txt
  put 1+length(x) - length(txt) into d
  add d to word 2 of sc
  add d to word 4 of sc
  return thsnd & hndrd
end myNumberFormat

on enterInField
  put the selectedChunk into sc
  put me into txt
  replace "." with empty in txt
  replace "," with "." in txt
  if txt is not a number then
    put myNumberFormat(0) into me
    exit enterInfield
  end if
  put myNumberFormat(txt) into me
  select sc
end enterInField

on returnInField
  enterInField
end returnInField

Re: Format number

Posted: Mon Sep 24, 2018 9:37 am
by cbarbal
Thanks for the reply [-hh].

I have usually replaced "," by "." and "." by ",", to make it look good on the screen, and to save it to the database to reverse the operation.

According to the lesson on the dgH plugin, this format is correct, but it does not work out for me. http://lessons.livecode.com/m/4068/l/39 ... r-a-column

Regards,

Carles

Re: Format number

Posted: Mon Sep 24, 2018 4:10 pm
by [-hh]
Decimal separator is always the period (".").
How did you script the replacement?

Re: Format number

Posted: Mon Sep 24, 2018 4:43 pm
by cbarbal
Hi,

Column Builder's Format, in the Decimal separator. Not In the Pattern property

Re: Format number

Posted: Mon Sep 24, 2018 5:14 pm
by [-hh]
I know why I don't use DG. I do it all by myself. That works, and if not I know why :-)

Re: Format number

Posted: Mon Sep 24, 2018 6:39 pm
by cbarbal
I guess you should take more than three weeks with LiveCode :D

Re: Format number

Posted: Wed Sep 26, 2018 7:05 pm
by Zryip TheSlug
I was in touch with Carles and found he didn't installed the DGH's script into the column to format.

The problem is now solved. Thanks guys for the help.