Format number

Moderators: heatherlaine, kevinmiller, robinmiller, Zryip TheSlug

Post Reply
cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Format number

Post by cbarbal » Sun Sep 23, 2018 7:44 pm

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
Attachments
LiveCode002.jpg

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Format number

Post by [-hh] » Mon Sep 24, 2018 1:23 am

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
shiftLock happens

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Format number

Post by cbarbal » Mon Sep 24, 2018 9:37 am

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Format number

Post by [-hh] » Mon Sep 24, 2018 4:10 pm

Decimal separator is always the period (".").
How did you script the replacement?
shiftLock happens

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Format number

Post by cbarbal » Mon Sep 24, 2018 4:43 pm

Hi,

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Format number

Post by [-hh] » Mon Sep 24, 2018 5:14 pm

I know why I don't use DG. I do it all by myself. That works, and if not I know why :-)
shiftLock happens

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Format number

Post by cbarbal » Mon Sep 24, 2018 6:39 pm

I guess you should take more than three weeks with LiveCode :D

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Format number

Post by Zryip TheSlug » Wed Sep 26, 2018 7:05 pm

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.
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

Post Reply

Return to “Data Grid Helper”