Commit b2e3b26e authored by Morten Welinder's avatar Morten Welinder

Locale improvements.

parent c8acae2d
1999-06-01 Morten Welinder <terra@diku.dk>
* src/format.c (format_value): Mark format for translation.
(format_number): Locale improvements.
* src/parser.y (yylex): Translate locale's decimal point into a
dot.
(gnumeric_expr_parser): Extract locale's decimal point.
1999-06-01 Akira Higuchi <a-higuti@math.sci.hokudai.ac.jp>
* src/gnumeric-util.c (font_change_component): Extend the size of
......
1999-06-01 Morten Welinder <terra@diku.dk>
* src/format.c (format_value): Mark format for translation.
(format_number): Locale improvements.
* src/parser.y (yylex): Translate locale's decimal point into a
dot.
(gnumeric_expr_parser): Extract locale's decimal point.
1999-06-01 Akira Higuchi <a-higuti@math.sci.hokudai.ac.jp>
* src/gnumeric-util.c (font_change_component): Extend the size of
......
1999-06-01 Morten Welinder <terra@diku.dk>
* src/format.c (format_value): Mark format for translation.
(format_number): Locale improvements.
* src/parser.y (yylex): Translate locale's decimal point into a
dot.
(gnumeric_expr_parser): Extract locale's decimal point.
1999-06-01 Akira Higuchi <a-higuti@math.sci.hokudai.ac.jp>
* src/gnumeric-util.c (font_change_component): Extend the size of
......
1999-06-01 Morten Welinder <terra@diku.dk>
* src/format.c (format_value): Mark format for translation.
(format_number): Locale improvements.
* src/parser.y (yylex): Translate locale's decimal point into a
dot.
(gnumeric_expr_parser): Extract locale's decimal point.
1999-06-01 Akira Higuchi <a-higuti@math.sci.hokudai.ac.jp>
* src/gnumeric-util.c (font_change_component): Extend the size of
......
......@@ -27,6 +27,7 @@
#include <time.h>
#include <math.h>
#include <locale.h>
#include <limits.h>
#include <ctype.h>
#ifdef HAVE_IEEEFP_H
# include <ieeefp.h>
......@@ -39,6 +40,11 @@
/* Points to the locale information for number display */
static struct lconv *lc;
#define DECIMAL_CHAR_OF_LC(lc) ((lc)->decimal_point[0] ? (lc)->decimal_point[0] : '.')
#define THOUSAND_CHAR_OF_LC(lc) ((lc)->thousands_sep[0] ? (lc)->thousands_sep[0] : ',')
#define CHAR_DECIMAL (CHAR_MAX + 1)
#define CHAR_THOUSAND (CHAR_MAX + 2)
static void style_entry_free (gpointer data, gpointer user_data);
......@@ -679,17 +685,23 @@ format_number (gdouble number, const StyleFormatEntry *style_format_entry)
struct tm *time_split = 0;
char *res;
if (!lc)
lc = localeconv ();
memset (&info, 0, sizeof (info));
if (number < 0.0){
info.negative = TRUE;
number = -number;
}
if (!lc)
lc = localeconv ();
while (*format){
switch (*format){
int c = *format;
if (c == DECIMAL_CHAR_OF_LC (lc))
c = CHAR_DECIMAL;
else if (c == THOUSAND_CHAR_OF_LC (lc))
c = CHAR_THOUSAND;
switch (c) {
case '#':
can_render_number = 1;
if (info.decimal_separator_seen)
......@@ -716,20 +728,20 @@ format_number (gdouble number, const StyleFormatEntry *style_format_entry)
}
break;
case ',': case '.': {
if (*format == lc->decimal_point [0]){
int c = *(format+1);
case CHAR_DECIMAL: {
int c = *(format+1);
can_render_number = 1;
if (c && (c != '0' && c != '#' && c != '?'))
number /= 1000;
else
info.decimal_separator_seen = TRUE;
break;
} else {
info.comma_separator_seen = TRUE;
break;
}
can_render_number = 1;
if (c && (c != '0' && c != '#' && c != '?'))
number /= 1000;
else
info.decimal_separator_seen = TRUE;
break;
}
case CHAR_THOUSAND: {
info.comma_separator_seen = TRUE;
break;
}
case 'E': case 'e':
......@@ -750,8 +762,8 @@ format_number (gdouble number, const StyleFormatEntry *style_format_entry)
}
/* FIXME: this is a gross hack */
{
char buffer [40];
sprintf (buffer, "%g", number);
char buffer [40 + DBL_DIG];
sprintf (buffer, "%.*g", DBL_DIG, number);
g_string_append (result, buffer);
goto finish;
......@@ -1003,16 +1015,16 @@ format_value (StyleFormat *format, const Value *value, StyleColor **color)
switch (value->type){
case VALUE_FLOAT:
if (is_general){
if (floor (value->v.v_float) == value->v.v_float)
entry.format = "0";
else
entry.format = "0.0########";
}
if (finite (value->v.v_float))
if (finite (value->v.v_float)) {
if (is_general){
if (floor (value->v.v_float) == value->v.v_float)
entry.format = "0";
else
entry.format = _("0.0########");
}
v = format_number (value->v.v_float, &entry);
else
return g_strdup ("#VAL");
} else
return g_strdup (_("#VAL!"));
break;
case VALUE_INTEGER:
......
......@@ -10,6 +10,7 @@
#include <config.h>
#include <ctype.h>
#include <string.h>
#include <locale.h>
#include <gnome.h>
#include "gnumeric.h"
#include "number-match.h"
......@@ -69,6 +70,9 @@ static int parser_col, parser_row;
/* The suggested format to use for this expression */
static const char **parser_desired_format;
/* Locale info. */
static char parser_decimal_point;
static ExprTree **parser_result;
#define p_new(type) ((type *) alloc_buffer ((unsigned) sizeof (type)))
......@@ -381,6 +385,10 @@ int yylex (void)
if (c == '(' || c == ',' || c == ')')
return c;
/* Translate locale's decimal marker into a dot. */
if (c == parser_decimal_point)
c = '.';
switch (c){
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': case '.': {
......@@ -736,6 +744,8 @@ ParseErr
gnumeric_expr_parser (const char *expr, Sheet *sheet, int col, int row,
const char **desired_format, ExprTree **result)
{
struct lconv *locinfo;
parser_error = PARSE_OK;
parser_expr = expr;
parser_sheet = sheet;
......@@ -747,6 +757,13 @@ gnumeric_expr_parser (const char *expr, Sheet *sheet, int col, int row,
if (parser_desired_format)
*parser_desired_format = NULL;
locinfo = localeconv ();
if (locinfo->decimal_point && locinfo->decimal_point[0] &&
locinfo->decimal_point[1] == 0)
parser_decimal_point = locinfo->decimal_point[0];
else
parser_decimal_point = '.';
yyparse ();
if (parser_error == PARSE_OK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment