Now that I have a working view, how do I format the numbers to display in a certain way? Say #,###.##
El Sunday, December 27, 2020 a la(s) 8:37:44 AM UTC-3, fbek...@gmail.com escribió:
Now that I have a working view, how do I format the numbers to display in a certain way? Say #,###.##Hi FB.
TextEdit has a typeconverter property. You can create a NumberToText subclass to format the numbers as you wish and use it in your views.
-- Sergio Del Franco.
Thanks Sergio for the tip, it was quite illuminating. Though it left me wondering how am I going to do that. I went browsing TextEdit and TypeConverter, and also read chapter 7 of 'the Dolphin Smalltalk Companion' book to form a plan. Working on it nowand will post the code when done.
FB
On Sunday, December 27, 2020 at 11:00:46 PM UTC+2, sdelf...@gmail.com wrote:
El Sunday, December 27, 2020 a la(s) 8:37:44 AM UTC-3, fbek...@gmail.com escribió:
Now that I have a working view, how do I format the numbers to display in a certain way? Say #,###.##Hi FB.
TextEdit has a typeconverter property. You can create a NumberToText subclass to format the numbers as you wish and use it in your views.
-- Sergio Del Franco.
Really wondering why Dolphin 7.xx still doesn't have native support for number formatting!![...]
Anyway, this is the method I wrote to handle number formatting.
Number>>asTextWithFormatBy: groupNum groupWith: groupChar decimalWith: decimalChar decimalNum: decimals[...]
"Format a number as ###,###.## | groupNum: anInteger; groupChar: aChar; decimalChar: aChar; decimals: anInteger"
El Tuesday, January 5, 2021 a la(s) 11:48:18 AM UTC-3, fbek...@gmail.com escribió:
Really wondering why Dolphin 7.xx still doesn't have native support for number formatting!![...]
Anyway, this is the method I wrote to handle number formatting.
Number>>asTextWithFormatBy: groupNum groupWith: groupChar decimalWith: decimalChar decimalNum: decimals[...]
"Format a number as ###,###.## | groupNum: anInteger; groupChar: aChar; decimalChar: aChar; decimals: anInteger"
You should use Locale >> #printFloat:on:format::
String streamContents: [:stream |
Locale default
printFloat: 1234.56
on: stream
format: (
NUMBERFMTW new
Grouping: 3;
thousandSeparator: ',';
decimalSeparator: '.';
decimalPlaces: 3;
yourself
).
].
-- Sergio Del Franco
Yes! This is what I was looking for!
Experimenting with the code now...
Thanks Sergio.
FB
On Saturday, January 9, 2021 at 2:00:55 PM UTC+2, sdelf...@gmail.com wrote:
El Tuesday, January 5, 2021 a la(s) 11:48:18 AM UTC-3, fbek...@gmail.com escribió:
Really wondering why Dolphin 7.xx still doesn't have native support for number formatting!![...]
Anyway, this is the method I wrote to handle number formatting.
Number>>asTextWithFormatBy: groupNum groupWith: groupChar decimalWith: decimalChar decimalNum: decimals[...]
"Format a number as ###,###.## | groupNum: anInteger; groupChar: aChar; decimalChar: aChar; decimals: anInteger"
You should use Locale >> #printFloat:on:format::
String streamContents: [:stream |
Locale default
printFloat: 1234.56
on: stream
format: (
NUMBERFMTW new
Grouping: 3;
thousandSeparator: ',';
decimalSeparator: '.';
decimalPlaces: 3;
yourself
).
].
-- Sergio Del Franco
Implementing the new code, my number formatting method now reads like this:finally decided against the change. In the above, I have added the last 2 properties (LeadingZero & NegativeOrder) more as a mental note, and for future reference, if necessary.
Number >> asTextWithGrouping: groupNum groupSeparator: groupChar decimalSeparator: decimalChar decimalPlaces: decimals
"Format the number as ###,###.## | groupNum: anInteger; groupChar: aString; decimalChar: aString; decimals: anInteger"
^String streamContents: [:strm | Locale default printFloat: self asFloat on: strm format: (
NUMBERFMTW new Grouping: groupNum ; thousandSeparator: groupChar ;
decimalSeparator: decimalChar ; decimalPlaces: decimals ;
LeadingZero: 1 ; NegativeOrder: 1 ;
yourself). ].
The receiver of the method is still <Number>, although it really could be any other object, and I have considered moving it to <String> instead, where it logically belongs - but that would add an argument for passing the number being formatted, so I
I then modified the converter #leftToRight method to call the new method: FB_NumberToText >> leftToRight: aNumberWindows local default). It remains very short of a full number formatting solution, similar to Windows products, e.g. in Excel. Again, for a programming environment that targets Windows exclusively, I thought Dolphin would offer a way to tap into all of
"Answers the result of converting aNumber to a String"
^aNumber asTextWithGrouping: 3 groupSeparator: ',' decimalSeparator: '.' decimalPlaces: 2 .
The rest of he code remained the same. With those 2 changes, my formatter was functional again.
Now for a quick discussion - from a beginner's point of view:
Using Locale >> #printFloat:on:format: was interesting and revealing but did not really do much more than my humble converter, included in the previous message, was able to offer (except for the possibility to auto format numbers according to the
Thanks Sergio for the assistance, happy hear your feedback.
FB
On Saturday, January 9, 2021 at 5:08:36 PM UTC+2, F Bek wrote:
Yes! This is what I was looking for!
Experimenting with the code now...
Thanks Sergio.
FB
On Saturday, January 9, 2021 at 2:00:55 PM UTC+2, sdelf...@gmail.com wrote:
El Tuesday, January 5, 2021 a la(s) 11:48:18 AM UTC-3, fbek...@gmail.com escribió:
Really wondering why Dolphin 7.xx still doesn't have native support for number formatting!![...]
Anyway, this is the method I wrote to handle number formatting.
Number>>asTextWithFormatBy: groupNum groupWith: groupChar decimalWith: decimalChar decimalNum: decimals[...]
"Format a number as ###,###.## | groupNum: anInteger; groupChar: aChar; decimalChar: aChar; decimals: anInteger"
You should use Locale >> #printFloat:on:format::
String streamContents: [:stream |
Locale default
printFloat: 1234.56
on: stream
format: (
NUMBERFMTW new
Grouping: 3;
thousandSeparator: ',';
decimalSeparator: '.';
decimalPlaces: 3;
yourself
).
].
-- Sergio Del Franco
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 60:58:58 |
Calls: | 6,654 |
Calls today: | 6 |
Files: | 12,200 |
Messages: | 5,331,524 |