diff options
Diffstat (limited to 'lib/csv')
| -rw-r--r-- | lib/csv/dataType.ml | 6 | ||||
| -rw-r--r-- | lib/csv/dataType.mli | 3 | ||||
| -rw-r--r-- | lib/csv/format.c | 8 | 
3 files changed, 11 insertions, 6 deletions
| diff --git a/lib/csv/dataType.ml b/lib/csv/dataType.ml index 1d2c7f9..6bf85ae 100644 --- a/lib/csv/dataType.ml +++ b/lib/csv/dataType.ml @@ -1,4 +1,4 @@ -external show_float : float -> string = "show_float" +external show_float : string -> float -> string = "show_float"  let match_date = Re.Str.regexp {|[0-9]+/[0-9]+/[0-9]+|} @@ -9,11 +9,11 @@ type t =    | Integer of int    | Float of float -let to_string = function +let to_string locale = function    | Null -> ""    | Error s -> s    | Integer i -> string_of_int i -  | Float f -> show_float f +  | Float f -> show_float locale f    | Content c -> (        match String.starts_with ~prefix:"0" c with        | false -> c diff --git a/lib/csv/dataType.mli b/lib/csv/dataType.mli index ebb8bc7..df5edf1 100644 --- a/lib/csv/dataType.mli +++ b/lib/csv/dataType.mli @@ -5,4 +5,5 @@ type t =    | Integer of int    | Float of float -val to_string : t -> string +val to_string : string -> t -> string +(** [to_string locale value] Format the text using the given locale *) diff --git a/lib/csv/format.c b/lib/csv/format.c index 31e4bbe..1394dc7 100644 --- a/lib/csv/format.c +++ b/lib/csv/format.c @@ -36,13 +36,17 @@ int asprintf(char *strp[], const char *fmt, ...) {      return r;}  #endif // asprintf -CAMLprim value show_float( value float_param ) +CAMLprim value show_float(value locale_param, value float_param )  { -    CAMLparam1( float_param ); +    CAMLparam2(locale_param, float_param );      CAMLlocal1( ml_data );      double f = Double_val(float_param);      char* raw_data; +    const char *s; +    s = String_val(locale_param); +    const char *saved_locale = setlocale(LC_NUMERIC, s);      int data_len = asprintf(&raw_data, "%f", f); +    setlocale(LC_NUMERIC, saved_locale);      ml_data = caml_copy_string( raw_data );      free(raw_data);      CAMLreturn( ml_data ); | 
