Re: Negative Numbers and NumberFormat
Oh that is interesting. Each number has to be a separate argument. That is something I did not glean from reading the docs a while back. Bob S On Apr 6, 2017, at 14:26 , Paul Dupuis via use-livecode mailto:use-livecode@lists.runrev.com>> wrote: put format("%03d.%03d.%03d.%03d",192,168,1,1) produces 192.168.001.001 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 4/6/2017 5:04 PM, Bob Sneidar via use-livecode wrote: > put format("00:00:00", "9:50:00") produces 00:00:00. > put format("##:##:##", "9:50:00") produces ##:##:##. > put format("nnn.nnn.nnn.nnn", "192.168.1.1") produces nnn.nnn.nnn.nnn put format("%2d:%02d:%02d", 9,50,0) produces 9:50:00 put format("%02d:%02d:%02d", 9,50,0) produces 09:50:00 put format("%0d.%0d.%0d.%0d",192,168,1,1) produces 192.168.1.1 put format("%03d.%03d.%03d.%03d",192,168,1,1) produces 192.168.001.001 I am not sure there is any delimited set of strings or numeric information you can't format. I do get that "00:00:00" is more intuitive than "%02d:%02d:%02d", which is why I suspect it is just the learning curve of understanding the syntax of the format function that prevents more people from using it. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
put format("00:00:00", "9:50:00") produces 00:00:00. put format("##:##:##", "9:50:00") produces ##:##:##. put format("nnn.nnn.nnn.nnn", "192.168.1.1") produces nnn.nnn.nnn.nnn Point being, format is great for formatting NUMBERS, not converting truncated numeric values in between delimiters or inserting literal string values in the appropriate places. Some may not see the need for this, or can thing of one off methods for doing each of these. So can I. I just don't like solving a problem over and over, and once solved I like to share that with others. As I said, Excel does this pretty well. I just need to mimic what they are doing. The trick would be to find the start and end character of actual numeric values in a string and replace them with reformatted versions in the format string. So " 1.55" with a format string of "00.000%" would return "01.550%" (not that you would need that, but you get the point.) Bob S > On Apr 6, 2017, at 11:13 , hh via use-livecode > wrote: > > You forgot to give examples for Bob's original problem? > The negative numbers ... ;-) > >> Paul D. wrote: > >>> put format("$%0.2f",tMoney) into msg >>> >>> for tMoney = 5.55, you get $5.55 >>> for tMoney = 5.3, you get $5.33 >>> >>> want a space between the $, then use >>> put format("$ %0.2f",tMoney) into msg >>> >>> want a leading zero and minimum of 2 digits before the decimal point >>> put format("$ %05.2f",5.553) into msg > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Okay, put format("$ %05.2f",-5.553) into msg gives $ -5.55 I am sure there is some formatting someone would want that can not be done with the format function, but most can and without spending the time to exhaustively test, I suspect that anything you can do with numberFormat you can do with format. On 4/6/2017 2:13 PM, hh via use-livecode wrote: > You forgot to give examples for Bob's original problem? > The negative numbers ... ;-) > >> Paul D. wrote: >>> put format("$%0.2f",tMoney) into msg >>> >>> for tMoney = 5.55, you get $5.55 >>> for tMoney = 5.3, you get $5.33 >>> >>> want a space between the $, then use >>> put format("$ %0.2f",tMoney) into msg >>> >>> want a leading zero and minimum of 2 digits before the decimal point >>> put format("$ %05.2f",5.553) into msg > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
You forgot to give examples for Bob's original problem? The negative numbers ... ;-) > Paul D. wrote: >> put format("$%0.2f",tMoney) into msg >> >> for tMoney = 5.55, you get $5.55 >> for tMoney = 5.3, you get $5.33 >> >> want a space between the $, then use >> put format("$ %0.2f",tMoney) into msg >> >> want a leading zero and minimum of 2 digits before the decimal point >> put format("$ %05.2f",5.553) into msg ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
I am curious why folks use numberFormat vs the format function (which is much more consistent and versatile). Is the issue the complexity of the formatting strings for the format function? put format("$%0.2f",tMoney) into msg for tMoney = 5.55, you get $5.55 for tMoney = 5.3, you get $5.33 want a space between the $, then use put format("$ %0.2f",tMoney) into msg want a leading zero and minimum of 2 digits before the decimal point put format("$ %05.2f",5.553) into msg I concur with Richards comment from Mark - it just seems like a low value and high risk work to change numberFormat at this point. I would think people should consider it deprecated in favor of format. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
I already have some functions for formatting numerical values I can submit for review. formatDate() is already in the masterLibrary. function formatMoney theValue -- strip out monetary symbols replace "$" with empty in theValue replace "¢" with empty in theValue switch case theValue = 0 or theValue >= 1 put format("$%1.2f", theValue) into theValue break case theValue >= 0 put format("%#.2f¢", theValue) into theValue break case theValue <= -1 replace "-" WITH empty in theValue put format("($%1.2f)", theValue) into theValue break case theValue < 0 replace "-" WITH empty in theValue put format("(%#.2f¢)", theValue) into theValue break end switch return theValue end formatMoney function formatPhone thePhoneNumber, theFormat -- text -- mid if theFormat is empty then put "classic" into theFormat end if if thePhoneNumber is empty then return thePhoneNumber end if put word 2 to -1 of thePhoneNumber into theExtension delete word 2 to -1 of thePhoneNumber repeat WITH i = 1 to the number of chars of thePhoneNumber if char i of thePhoneNumber is a number then put char i of thePhoneNumber after theNewValue end if end repeat put the length of theNewValue into theLength if theLength is not among the items of "7,10" then return thePhoneNumber && theExtension exit formatPhone end if put "-" before char -4 of theNewValue if theLength is 10 then if theFormat is "classic" then put ") " after char 3 of theNewValue put "(" before theNewValue else put "-" after char 3 of theNewValue end if end if if theExtension is not empty then put " " & theExtension after theNewValue return theNewValue end formatPhone On Apr 6, 2017, at 08:35 , Richard Gaskin via use-livecode mailto:use-livecode@lists.runrev.com>> wrote: Perhaps this raises a more interesting question: Should we consider creating a new more fully-featured function which not only behaves as we might find ideal for decimal values, but also supports formatting of phone numbers, currency, and other common display formats? Maybe a pair of functions would be useful so we could easily transform between display and calculation formats, something like: put formattedValue(".25", "currency-US") -- returns: $0.25 put rawValue("$0.25". "currency-US") -- returns: 0.25 Should there be some provision for doing that on a list where a column specifier could be supplied?: put rawValue(tSomeLlist, "currency-US", 2) -- returns the list with values in column 2 converted to calculable formats. This could be written in LC Script or LC Builder - might be a good community project -- Richard Gaskin ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Paul Dupuis wrote: > On 4/5/17 5:48 PM, Richard Gaskin via use-livecode wrote: >> >> Confirmed - running this script in v9dp6 and again all the way back >> in v6.0: >> >> on mouseUp >>set the numberformat to "###.###" >>put 2.5 + 2.5 into x >>set the numberformat to "000.000" >>put 2.5 + 2.5 into y >>put x &cr& y >> end mouseUp >> >> ...I get: >> >> 005.000 >> 005.000 > > NumberFormat on applies when the number is output or forced to convert > to a string (for example when doing string concatenation). The variant > script below: > > on mouseUp >set the numberformat to "###.###" >put 2.5 + 2.5 into x >put x & cr after msg >set the numberformat to "000.000" >put 2.5 + 2.5 into y >put y &cr after msg > end mouseUp > > results in: > > 005 > 005.000 D'oh! Yes, of course, I'd forgotten to make sure the value is coerced to a string for each unique output. Good catch. It still seems off though, on the left side of the decimal. I would have expected the first value to be "5", given that "#" provides a space only when needed. The LC Dict only discusses the distinction between "#" and "0" for numbers on the right side of the decimal, so I turned to "HyperTalk 2.2: The Book" for further guidance - and found what appear to be contradicting examples. Among the many examples listed on p.411 for the "numberFormat" property are: set the numberFormat to "#.000" - 0.25031 is displayed as .250 set the numberFormat to "#.###" - 0.25031 is displayed as .25 set the numberFormat to "#.000" - 0.25031 is displayed as 0.2503100 set the numberFormat to "#.000" - 0.25031 is displayed as 0.25031 In each of those examples, what's happening on the right side of the decimal follows predictable rules. But the left side seems inconsistent, in some cases using the "#" to force a leading 0 and in other cases not. The relevant portion of the book's text for that entry says: The number of zeroes before the decimal point is the minimum number of integer digits to display. HyperTalk always includes at least enough digits to specify the result of the calculation. If there are more digits in the number than the numberFormat calls for, HyperTalk displays all the digits. If there are fewer digits than the numberFormat calls for, HyperTalk adds leading zeroes to the beginning of the number. There's further discussion of what happens after the decimal, but for what happens before the decimal only "0" is discussed, with no mention of what "#" should do when on the left side of the decimal. The same omission is found (or more specifically, not found ) in the SuperTalk 3.0 Language Guide. Unable to find clarity on that, I decided to try each of those HyperTalk examples above in LC - here's what I got: set the numberFormat to "#.000" - 0.25031 is displayed as 0.250 set the numberFormat to "#.###" - 0.25031 is displayed as 0.25 set the numberFormat to "#.000" - 0.25031 is displayed as 0.2503100 set the numberFormat to "#.000" - 0.25031 is displayed as 0.25031 Summary: HyperTalk: I have no idea what it's doing. LiveCode: Either "#" or "0" to the left of the decimal will result in padding with leading 0s. LC is certainly more consistent, but is it what we'd expect or want? As Mark Waddingham noted, the engine code for numberFormat has been unchanged in such a long time that, regardless of what *might* be "best", it's unlikely to change at this point out of concern for scripts dependent on its current behavior. Perhaps this raises a more interesting question: Should we consider creating a new more fully-featured function which not only behaves as we might find ideal for decimal values, but also supports formatting of phone numbers, currency, and other common display formats? Maybe a pair of functions would be useful so we could easily transform between display and calculation formats, something like: put formattedValue(".25", "currency-US") -- returns: $0.25 put rawValue("$0.25". "currency-US") -- returns: 0.25 Should there be some provision for doing that on a list where a column specifier could be supplied?: put rawValue(tSomeLlist, "currency-US", 2) -- returns the list with values in column 2 converted to calculable formats. This could be written in LC Script or LC Builder - might be a good community project -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
I've created a monster. All the more reason to depricate numberformat and go with some kind of formatNumber() function like Excel has. I'll have a go today sometime. Bob S > On Apr 5, 2017, at 17:27 , Paul Dupuis via use-livecode > wrote: > > On 4/5/2017 7:42 PM, J. Landman Gay via use-livecode wrote: >> On 4/5/17 5:48 PM, Richard Gaskin via use-livecode wrote: >>> Jacque wrote: >>> HyperCard distinguished between "#" and "0" and produced different results. It sounds like LC doesn't? >>> >>> Confirmed - running this script in v9dp6 and again all the way back in >>> v6.0: >>> >>> on mouseUp >>> set the numberformat to "###.###" >>> put 2.5 + 2.5 into x >>> set the numberformat to "000.000" >>> put 2.5 + 2.5 into y >>> put x &cr& y >>> end mouseUp >>> >>> ...I get: >>> >>> 005.000 >>> 005.000 > > NumberFormat on applies when the number is output or forced to convert > to a string (for example when doing string concatenation). The variant > script below: > > on mouseUp > set the numberformat to "###.###" > put 2.5 + 2.5 into x > put x & cr after msg > set the numberformat to "000.000" > put 2.5 + 2.5 into y > put y &cr after msg > end mouseUp > > results in: > > 005 > 005.000 > > In the message box. Just another data point for the discussion. > > > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 4/5/2017 7:42 PM, J. Landman Gay via use-livecode wrote: > On 4/5/17 5:48 PM, Richard Gaskin via use-livecode wrote: >> Jacque wrote: >> >>> HyperCard distinguished between "#" and "0" and produced different >>> results. It sounds like LC doesn't? >> >> Confirmed - running this script in v9dp6 and again all the way back in >> v6.0: >> >> on mouseUp >>set the numberformat to "###.###" >>put 2.5 + 2.5 into x >>set the numberformat to "000.000" >>put 2.5 + 2.5 into y >>put x &cr& y >> end mouseUp >> >> ...I get: >> >> 005.000 >> 005.000 NumberFormat on applies when the number is output or forced to convert to a string (for example when doing string concatenation). The variant script below: on mouseUp set the numberformat to "###.###" put 2.5 + 2.5 into x put x & cr after msg set the numberformat to "000.000" put 2.5 + 2.5 into y put y &cr after msg end mouseUp results in: 005 005.000 In the message box. Just another data point for the discussion. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 4/5/17 5:48 PM, Richard Gaskin via use-livecode wrote: Jacque wrote: HyperCard distinguished between "#" and "0" and produced different results. It sounds like LC doesn't? Confirmed - running this script in v9dp6 and again all the way back in v6.0: on mouseUp set the numberformat to "###.###" put 2.5 + 2.5 into x set the numberformat to "000.000" put 2.5 + 2.5 into y put x &cr& y end mouseUp ...I get: 005.000 005.000 Where I would have expected: 5.0 005.000 Who wants to file the bug report? The fact that the dictionary also doesn't discriminate implies it isn't a bug, it's intentional, and the hash/zero options are for HC compatibility only. I can't remember if MC worked as I would have expected. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Jacque wrote: > HyperCard distinguished between "#" and "0" and produced different > results. It sounds like LC doesn't? Confirmed - running this script in v9dp6 and again all the way back in v6.0: on mouseUp set the numberformat to "###.###" put 2.5 + 2.5 into x set the numberformat to "000.000" put 2.5 + 2.5 into y put x &cr& y end mouseUp ...I get: 005.000 005.000 Where I would have expected: 5.0 005.000 Who wants to file the bug report? -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 4/5/17 2:07 PM, Mark Waddingham via use-livecode wrote: I should say the bit of engine code which does parsing and application of the numberformat has been left untouched in terms of what it does for as long as I can remember... It is one of those places where a subtle change could break apps quite easily as it is somewhat hard to see precisely what it should and should not do! HyperCard distinguished between "#" and "0" and produced different results. It sounds like LC doesn't? -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Yup. I have thought for a long time that there should be a formatNumber() function that did almost exactly what Excel does in terms of formatting a number. I will have to look into that. I'll post it if I throw one together. Should be easy given the string operations LC is capable of. Bob S On Apr 5, 2017, at 12:07 , Mark Waddingham via use-livecode mailto:use-livecode@lists.runrev.com>> wrote: I should say the bit of engine code which does parsing and application of the numberformat has been left untouched in terms of what it does for as long as I can remember... It is one of those places where a subtle change could break apps quite easily as it is somewhat hard to see precisely what it should and should not do! Mark ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
I should say the bit of engine code which does parsing and application of the numberformat has been left untouched in terms of what it does for as long as I can remember... It is one of those places where a subtle change could break apps quite easily as it is somewhat hard to see precisely what it should and should not do! Mark Sent from my iPhone > On 5 Apr 2017, at 19:56, Mark Waddingham via use-livecode > wrote: > >> On 2017-04-05 20:28, Bob Sneidar via use-livecode wrote: >> And here is an oddity again. In the dictionary, there is no mention of >> spaces or any other character besides "0.#" being valid in a >> numberformat string, but: >> set the numberformat to " 00";put -09+0 & ":" & 00+0 & ":" & 00+0 >> produces -09:000:000 >> In fact, you can put ANYTHING in place of a 0, and it will treat it as >> though it were a 0! >> Wha??? > > I think the numberFormat is perhaps just appearing to do more than it > actually does. Basically it allows you to set the field width before and > after a decimal point. So: > > set the numberFormat to "." > > Will result in the engine padding either side of the decimal point up to the > specified number of chars with 0 if the length of that part is less than the > specified width. > > Whether or not the '-' sign should be included in these width calculations I > guess is a matter of debate... > > Warmest Regards, > > Mark. > > P.S. Apologies for missing your actual point before, I should have read the > thread in more detail before posting ;) > > -- > Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ > LiveCode: Everyone can create apps > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 2017-04-05 20:28, Bob Sneidar via use-livecode wrote: And here is an oddity again. In the dictionary, there is no mention of spaces or any other character besides "0.#" being valid in a numberformat string, but: set the numberformat to " 00";put -09+0 & ":" & 00+0 & ":" & 00+0 produces -09:000:000 In fact, you can put ANYTHING in place of a 0, and it will treat it as though it were a 0! Wha??? I think the numberFormat is perhaps just appearing to do more than it actually does. Basically it allows you to set the field width before and after a decimal point. So: set the numberFormat to "." Will result in the engine padding either side of the decimal point up to the specified number of chars with 0 if the length of that part is less than the specified width. Whether or not the '-' sign should be included in these width calculations I guess is a matter of debate... Warmest Regards, Mark. P.S. Apologies for missing your actual point before, I should have read the thread in more detail before posting ;) -- Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ LiveCode: Everyone can create apps ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
And here is an oddity again. In the dictionary, there is no mention of spaces or any other character besides "0.#" being valid in a numberformat string, but: set the numberformat to " 00";put -09+0 & ":" & 00+0 & ":" & 00+0 produces -09:000:000 In fact, you can put ANYTHING in place of a 0, and it will treat it as though it were a 0! Wha??? Bob S ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
That was my point, that the sign should not take up one of the digits in numberformat 00. And thank you for your explanation about strings being strings until math was done on them. In my timeCalc() function however, I already convery everything to seconds and just before conatenating HH, MM and SS, I add 0 to each one. set the numberformat to "00" return tTotalHours +0 & ":" & tTotalMinutes +0 & ":" & tTotalSeconds +0 If tTotalHours is negative I get -H if it is less than 10. Like I said it's not a big deal. I can always work around it. Bob S > On Apr 5, 2017, at 10:21 , Mark Waddingham via use-livecode > wrote: > > It looks odd, but is explainable. It has nothing to do with '-' eating up > places for 0 in the numberFormat, but to do with the type of things in > that expression: ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 2017-04-05 19:21, Mark Waddingham via use-livecode wrote: The latter bit about 'not being able to do arithmetic' might sound odd but it is a reflection of the finiteness of computers. Just correcting myself: 'finiteness of computers' was the wrong thing to say here - if you can represent a number as a decimal string in a computer then it is clearly finite as the amount of memory you have is finite. Therefore, it is more about 'needing to do arithmetic quickly on computers' (for some definition of 'quickly'). Mark. -- Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ LiveCode: Everyone can create apps ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
On 2017-04-03 19:11, Bob Sneidar via use-livecode wrote: Was anyone aware that the sign takes up one of the digital in number format? For instance, set the numberformat to "00";put -1 +0 & ":" & 0 +0 & ":" & 0 +0 returns: -1:00:00 but set the numberformat to "00";put -12 +0 & ":" & 0 +0 & ":" & 0 +0 returns: -12:00:00 Does no one else find that odd?? It looks odd, but is explainable. It has nothing to do with '-' eating up places for 0 in the numberFormat, but to do with the type of things in that expression: Contrast: set the numberformat to "00";put 0+0 & ":" & 0+0 & ":" & 0+0 => 00:00:00 And: set the numberformat to "00";put 0 & ":" & 0 & ":" & 0 => 0:0:0 The reason here is that the token 0 in a script is actually treated as a string *until* you do something to it which turns it into a number. Only numbers are subject to numberFormat. So, in the first case you are doing: put NUMBER & ":" & NUMBER & ":" & NUMBER In the second case you are doing: put STRING & ":" & STRING & ":" & STRING The & operator requires two strings, so in the first case the NUMBERs are being converted to strings (and thus subject to numberFormat) whereas in the second case they are already STRINGs so no conversion takes place. I class this as an anomaly. The correction would be that any token in script which *looks* like a number should act like a number in terms of string conversion rules (including the application of numberFormat), even if it can't be represented exactly as a number. This rule would mean that as long as you don't attempt to do arithmetic on something which looks like a number, how it looks will be preserved. The latter bit about 'not being able to do arithmetic' might sound odd but it is a reflection of the finiteness of computers. For example, the engine currently uses IEEE doubles for all its arithmetic. Whilst such things can represent a very large number of numbers (2^60 different values or near enough), the actual range a double can represent is substantially bigger (many orders of magnitude bigger, in fact - something like -10^300 to +10^300). This results in there being many many string representations which map to the same double (for example 0 can be written as 0, 0.0, 0.00, 0.000, ...). Indeed, doubles only have about 15 digits of decimal precision, meaning that if your actual number has more than 15 non-zero digits before or after a lot of 0's then you'll get an approximation to the actual number (well, you'll get a number which is within DBL_EPSILON of the real number, anyway - this kind of stuff gets pernickety very very quickly). In actual fact, the above rule can be extended further - and perhaps expressed more succinctly as: If a string is converted to a number, then the actual conversion should not occur until it is absolutely needed. The point here is that formatting a (decimal) string representation of a number via numberFormat does not actually require conversion to an actual number - it can be done using the string representation alone - and doing it that way would mean that numbers would be preserved to look exactly as they did unless you actual poke them with arithmetic. Of course, you might argue that 'whats the point of numbers if you don't do arithmetic on them' - but it is often the case that our programs manipulate numbers without doing anything to them, we just need to know that 'they are numbers'. A good example is the json importers/exporters which exist. They do zero arithmetic - they merely import and export existing data. In that case it is very important that the data is preserved *as is* otherwise you can't roundtrip (i.e. import data, and immediately export without changing anything). Warmest Regards, Mark. -- Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/ LiveCode: Everyone can create apps ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Never mind. Bob S > On Apr 4, 2017, at 13:12 , hh via use-livecode > wrote: > Bob S. wrote: You should rather say the number format determines the num of DIGITS. >>> hh wrote: >>> That's what you wish to have (good idea). But it's not like that, its >>> the length of the number as string. >> Bob S. wrote >> Really? Then why does : >> set the numberformat to 0.0; put -.1 + 0 result in -0.1 ? > > You are mixing input methods and output methods. > > "-.x" (or ".x") is allowed as input, but then converted to > "-0.x" (or "0.x"). Just the same for "00.x" or "-00.x" > > *After* that the numberformat is applied (and doesn't cut if leading is > longer). That's why > > set the numberformat to "0.0" > put 0-".1", 0+"-0.1", 0+"-00.1" after s -- you may leave out quotes > set the numberformat to "00.0" > put 0-".1", 0+"-0.1", 0+"-00.1" after s -- you may leave out quotes > > both yield -0.1,-0.1,-0.1 (in LC 6/7/8/9). > > To see more clear the string length is applied to the number: > You can use _ANY_ other one-byte-char other than the separator ("."). > > set the numberformat to "ab.c" > is equivalent to > set the numberformat to "00.0" > > This is comfortable if you wish to have the numbers length > dependent on any string varibale's length: > > put "Bob.S" into str > set the numberformat to str > put 0-12 & " _and_ " & 0+13 > > yields -12.0 _and_ 013.0, as I said (in LC 6/7/8/9). > > *** Once again, I like and support your idea. *** > But I suggest to name it a feature request, not a bug: > > Perhaps the option to apply the numberformat to the absolute value > only and choose/apply a prefix: either +, -, space or empty? > The empty is for people who distinguish negative and positive nums > by labels only (debit and credit) or colors only (red and black). > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
>>> Bob S. wrote: >>> You should rather say the number format determines the num of DIGITS. >> hh wrote: >> That's what you wish to have (good idea). But it's not like that, its >> the length of the number as string. > Bob S. wrote > Really? Then why does : > set the numberformat to 0.0; put -.1 + 0 result in -0.1 ? You are mixing input methods and output methods. "-.x" (or ".x") is allowed as input, but then converted to "-0.x" (or "0.x"). Just the same for "00.x" or "-00.x" *After* that the numberformat is applied (and doesn't cut if leading is longer). That's why set the numberformat to "0.0" put 0-".1", 0+"-0.1", 0+"-00.1" after s -- you may leave out quotes set the numberformat to "00.0" put 0-".1", 0+"-0.1", 0+"-00.1" after s -- you may leave out quotes both yield -0.1,-0.1,-0.1 (in LC 6/7/8/9). To see more clear the string length is applied to the number: You can use _ANY_ other one-byte-char other than the separator ("."). set the numberformat to "ab.c" is equivalent to set the numberformat to "00.0" This is comfortable if you wish to have the numbers length dependent on any string varibale's length: put "Bob.S" into str set the numberformat to str put 0-12 & " _and_ " & 0+13 yields -12.0 _and_ 013.0, as I said (in LC 6/7/8/9). *** Once again, I like and support your idea. *** But I suggest to name it a feature request, not a bug: Perhaps the option to apply the numberformat to the absolute value only and choose/apply a prefix: either +, -, space or empty? The empty is for people who distinguish negative and positive nums by labels only (debit and credit) or colors only (red and black). ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Really? Then why does : set the numberformat to 0.0;put -.1 + 0 result in -0.1 ? Bob S > On Apr 3, 2017, at 16:55 , hh via use-livecode > wrote: > >> You should rather say the number format determines the num of DIGITS. > > That's what you wish to have (good idea). But it's not like that, its > the length of the number as string. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
> Bob S. worte: > I have a function for calculating the difference in time Then you mean -(01:00:00) and not (-01):(00):(00), quite different. AFAIK most languages do such time evaluations as follows 1) compute the time in seconds, 2) convert its absolute value to time format, and 3) if negative, put "-" before the formatted time. That is, the whole display is not an immediate result of setting the number format. > You should rather say the number format determines the num of DIGITS. That's what you wish to have (good idea). But it's not like that, its the length of the number as string. You gave the proof yourself. It's the same with the number formats from format(). Probably LC uses internally format() for its numberFormat. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
The time format is irrelevant. It just so happens I have a function for calculating the difference in time, and when the first character is a - I know the end time is earlier than the start time, which was what I was checking for. And I think you are mistaken. numberFormat sets the format for numeric values, not just any characters. You should rather say the number format determine the num of DIGITS. Signage is an acceptable part of a numeric value. A dollar sign or a comma for example are not. Still, if everyone expects that set the number format to "00"; return 0-1 should return -1, well then that's how it should be. Bob S > On Apr 3, 2017, at 15:49 , hh via use-livecode > wrote: > > TMHO, this could be a feature request rather than a bug report. > The zeros in the number format determine the num of characters > and "-" is one. > > Also we have -0 = 0. So what about "-01:-00:-00" ?? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
TMHO, this could be a feature request rather than a bug report. The zeros in the number format determine the num of characters and "-" is one. Also we have -0 = 0. So what about "-01:-00:-00" ?? > Bob S. wrote: > "-01:00:00"? > Yes I expected this. It's not that I cannot work around it, > it's just that it seems it ought to put 2 zeros where 2 zeros > are specified in the numberFormat and if it doesn't and should, > then I will file an (admittedly low priority) bug report. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Yes I expected this. It's not that I cannot work around it, it's just that it seems it ought to put 2 zeros where 2 zeros are specified in the numberFormat and if it doesn't and should, then I will file an (admittedly low priority) bug report. Bob S > On Apr 3, 2017, at 10:16 , dunbarx via use-livecode > wrote: > > -01:00:00 > > Craig Newman ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Negative Numbers and NumberFormat
Hi. Hmmm. When you say "...the sign takes up one of the digital " does this make it better or worse: set the numberformat to "00" put -1112 +0 & ":" & 0 +0 & ":" & 0 +0 or going the other way, with your top snippet, did you expect: -01:00:00 Craig Newman -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Negative-Numbers-and-NumberFormat-tp4713609p4713610.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Negative Numbers and NumberFormat
Was anyone aware that the sign takes up one of the digital in number format? For instance, set the numberformat to "00";put -1 +0 & ":" & 0 +0 & ":" & 0 +0 returns: -1:00:00 but set the numberformat to "00";put -12 +0 & ":" & 0 +0 & ":" & 0 +0 returns: -12:00:00 Does no one else find that odd?? Bob S ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode