digitalmars.D.learn - number formatting
- John C (5/5) Jan 12 2006 Are there any number formatting routines in Phobos? I couldn't see any, ...
- Carlos Santander (5/14) Jan 12 2006 There's std.string.format(). It works just like writef() except that it ...
- John C (4/17) Jan 12 2006 Well, of course I knew about string.format. But is there a format patter...
- Carlos Santander (5/26) Jan 12 2006 Oops, sorry. I didn't understand that. Apparently there's not, and it se...
- HienTau (4/13) Jan 13 2006 You can use the c-style sprintf to format numbers. Isn't exactly elegant...
- John C (10/21) Jan 13 2006 The "C-style sprintf" you mention *is* the C sprintf, and it doesn't han...
- HienTau (4/31) Jan 13 2006 "Right, I guess I'm looking at rolling my own stuff."
- Kris (10/16) Jan 13 2006 The ICU project has truly excellent support for this kind of thing, alth...
- John C (4/21) Jan 13 2006 Certainly. I'd be more than happy to collaborate on a proper D library f...
- John C (23/40) Jan 16 2006 Kris, may I send you the work I've done on this? So far I've got a gener...
- Kris (4/51) Jan 16 2006 Please do!
- Ivan Senji (2/54) Jan 16 2006 Nice. But: what about locales where Monday is the first day of week?
- John C (3/60) Jan 16 2006 You'd offset it with the 'firstDayOfWeek' property.
Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.
Jan 12 2006
John C escribió:Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.There's std.string.format(). It works just like writef() except that it returns a char[]. -- Carlos Santander Bernal
Jan 12 2006
"Carlos Santander" <csantander619 gmail.com> wrote in message news:dq6qik$1hed$1 digitaldaemon.com...John C escribió:Well, of course I knew about string.format. But is there a format pattern that will, for example, return 1500000 as "1,500,000"?Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.There's std.string.format(). It works just like writef() except that it returns a char[]. -- Carlos Santander Bernal
Jan 12 2006
John C escribió:"Carlos Santander" <csantander619 gmail.com> wrote in message news:dq6qik$1hed$1 digitaldaemon.com...Oops, sorry. I didn't understand that. Apparently there's not, and it seems that C's printf doesn't support that either (AFAICT). -- Carlos Santander BernalJohn C escribió:Well, of course I knew about string.format. But is there a format pattern that will, for example, return 1500000 as "1,500,000"?Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.There's std.string.format(). It works just like writef() except that it returns a char[]. -- Carlos Santander Bernal
Jan 12 2006
John C schrieb:Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.You can use the c-style sprintf to format numbers. Isn't exactly elegant but seems to work. See date.d (in src\phobos\std) for uses. HienTau
Jan 13 2006
"HienTau" <hientau.mail gmail.com> wrote in message news:dq87pk$iq6$1 digitaldaemon.com...John C schrieb:The "C-style sprintf" you mention *is* the C sprintf, and it doesn't handle thousand separators. I'd already tried it. This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.You can use the c-style sprintf to format numbers. Isn't exactly elegant but seems to work. See date.d (in src\phobos\std) for uses. HienTau
Jan 13 2006
John C schrieb:"HienTau" <hientau.mail gmail.com> wrote in message news:dq87pk$iq6$1 digitaldaemon.com..."Right, I guess I'm looking at rolling my own stuff." I guess this is *the* motto for convenience d-programming until at least version 1.0 ;-)John C schrieb:The "C-style sprintf" you mention *is* the C sprintf, and it doesn't handle thousand separators. I'd already tried it. This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.Are there any number formatting routines in Phobos? I couldn't see any, but thought I'd ask. I simply want to get a number back as a string with thousand separators. If not, I think Win32's GetNumberFormat will do what I want. Cheers.You can use the c-style sprintf to format numbers. Isn't exactly elegant but seems to work. See date.d (in src\phobos\std) for uses. HienTau
Jan 13 2006
"John C" <johnch_atms hotmail.com> wrote... [snip]This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 13 2006
"Kris" <fu bar.com> wrote in message news:dq8o9c$12rs$1 digitaldaemon.com..."John C" <johnch_atms hotmail.com> wrote... [snip]Certainly. I'd be more than happy to collaborate on a proper D library for this. I'm going to study some of the existing packages (.NET, Java, ICU, STL) to see what kind of work is required and how it's implemented.This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 13 2006
"Kris" <fu bar.com> wrote in message news:dq8o9c$12rs$1 digitaldaemon.com..."John C" <johnch_atms hotmail.com> wrote... [snip]Kris, may I send you the work I've done on this? So far I've got a general class to represent locales on the user's system, several classes for date/time, number and text formatting support, a set of calendars (Gregorian, Japanese, Hijri etc), and some string-related functions. The following example lists all the calendars supported by a locale. Culture[] allCultures = Culture.getCultures(CultureTypes.ALL); foreach (Culture culture; allCultures) { writefln("Culture: " ~ culture.name ~ " - " ~ culture.displayName); Calendar[] calendars = culture.optionalCalendars; writefln("Calendars:"); foreach (Calendar cal; calendars) { writefln("\t" ~ cal.toString()); } writefln(); } This example prints the days of the week in French: Culture culture = new Culture("fr-fr"); for (DayOfWeek dayOfWeek = DayOfWeek.SUNDAY; dayOfWeek <= DayOfWeek.SATURDAY; dayOfWeek++) { writefln(culture.dateTimeFormat.getDayName(dayOfWeek)); } John.This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 16 2006
Please do! use this account: someidiot at at at earthlink dot . dot net "John C" <johnch_atms hotmail.com> wrote in message news:dqghld$1llj$1 digitaldaemon.com..."Kris" <fu bar.com> wrote in message news:dq8o9c$12rs$1 digitaldaemon.com..."John C" <johnch_atms hotmail.com> wrote... [snip]Kris, may I send you the work I've done on this? So far I've got a general class to represent locales on the user's system, several classes for date/time, number and text formatting support, a set of calendars (Gregorian, Japanese, Hijri etc), and some string-related functions. The following example lists all the calendars supported by a locale. Culture[] allCultures = Culture.getCultures(CultureTypes.ALL); foreach (Culture culture; allCultures) { writefln("Culture: " ~ culture.name ~ " - " ~ culture.displayName); Calendar[] calendars = culture.optionalCalendars; writefln("Calendars:"); foreach (Calendar cal; calendars) { writefln("\t" ~ cal.toString()); } writefln(); } This example prints the days of the week in French: Culture culture = new Culture("fr-fr"); for (DayOfWeek dayOfWeek = DayOfWeek.SUNDAY; dayOfWeek <= DayOfWeek.SATURDAY; dayOfWeek++) { writefln(culture.dateTimeFormat.getDayName(dayOfWeek)); } John.This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 16 2006
John C wrote:"Kris" <fu bar.com> wrote in message news:dq8o9c$12rs$1 digitaldaemon.com...Nice. But: what about locales where Monday is the first day of week?"John C" <johnch_atms hotmail.com> wrote... [snip]Kris, may I send you the work I've done on this? So far I've got a general class to represent locales on the user's system, several classes for date/time, number and text formatting support, a set of calendars (Gregorian, Japanese, Hijri etc), and some string-related functions. The following example lists all the calendars supported by a locale. Culture[] allCultures = Culture.getCultures(CultureTypes.ALL); foreach (Culture culture; allCultures) { writefln("Culture: " ~ culture.name ~ " - " ~ culture.displayName); Calendar[] calendars = culture.optionalCalendars; writefln("Calendars:"); foreach (Calendar cal; calendars) { writefln("\t" ~ cal.toString()); } writefln(); } This example prints the days of the week in French: Culture culture = new Culture("fr-fr"); for (DayOfWeek dayOfWeek = DayOfWeek.SUNDAY; dayOfWeek <= DayOfWeek.SATURDAY; dayOfWeek++) { writefln(culture.dateTimeFormat.getDayName(dayOfWeek)); }This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 16 2006
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dqhavm$2fmg$1 digitaldaemon.com...John C wrote:You'd offset it with the 'firstDayOfWeek' property."Kris" <fu bar.com> wrote in message news:dq8o9c$12rs$1 digitaldaemon.com...Nice. But: what about locales where Monday is the first day of week?"John C" <johnch_atms hotmail.com> wrote... [snip]Kris, may I send you the work I've done on this? So far I've got a general class to represent locales on the user's system, several classes for date/time, number and text formatting support, a set of calendars (Gregorian, Japanese, Hijri etc), and some string-related functions. The following example lists all the calendars supported by a locale. Culture[] allCultures = Culture.getCultures(CultureTypes.ALL); foreach (Culture culture; allCultures) { writefln("Culture: " ~ culture.name ~ " - " ~ culture.displayName); Calendar[] calendars = culture.optionalCalendars; writefln("Calendars:"); foreach (Calendar cal; calendars) { writefln("\t" ~ cal.toString()); } writefln(); } This example prints the days of the week in French: Culture culture = new Culture("fr-fr"); for (DayOfWeek dayOfWeek = DayOfWeek.SUNDAY; dayOfWeek <= DayOfWeek.SATURDAY; dayOfWeek++) { writefln(culture.dateTimeFormat.getDayName(dayOfWeek)); }This reminds me that one of the gaping holes in Phobos is support for locales. Open std.dateparse to see how bad it is - English day and month names are hard coded! There should be a localisation module that might incorporate numeric formatting (the latter would probably depend on the former, eg for currencies). Right, I guess I'm looking at rolling my own stuff.The ICU project has truly excellent support for this kind of thing, although it is industrial strength ~ can be a bit heavyweight for personal use? They have all kinds of tools for externalizing and migrating/managing I18N concerns, and there's a D wrapper for ICU in the Mango library. I'm also interested in a lightweight implementation (Mango has a bunch of support functions to make it happen) ~ just haven't got around to hooking up the pieces yet. If ICU is not appropriate for your needs, and you think it's a reasonably idea, we might combine efforts?
Jan 16 2006