diff options
| author | mbkma <[email protected]> | 2025-08-14 21:25:45 +0200 |
|---|---|---|
| committer | mbkma <[email protected]> | 2025-08-14 21:25:45 +0200 |
| commit | ff3858a325c4d3ad172834b74f347ca9ab5dd81e (patch) | |
| tree | 02e18f4938b314a9b0467d5d90282f68dac5c820 | |
| parent | 7ef327f6f269c7a49357e001cd41d7aaf5807749 (diff) | |
| download | mate-calc-ff3858a325c4d3ad172834b74f347ca9ab5dd81e.tar.bz2 mate-calc-ff3858a325c4d3ad172834b74f347ca9ab5dd81e.tar.xz | |
The comma decimal separator support has been implemented successfully. Now mate-calc supports both period (.) and comma (,) as decimal separators.
| -rw-r--r-- | src/math-equation.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/math-equation.c b/src/math-equation.c index 2ce3ab8..c7a4ef5 100644 --- a/src/math-equation.c +++ b/src/math-equation.c @@ -250,6 +250,25 @@ reformat_separators(MathEquation *equation) else if (c == mp_serializer_get_radix(equation->priv->serializer)) { in_number = in_radix = TRUE; } + else if (c == ',' && in_number) { + /* Convert comma to proper radix character for French decimal separator support */ + GtkTextIter start, end; + gchar buffer[7]; + gint len; + + gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(equation), &start, offset); + gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(equation), &end, offset + 1); + gtk_text_buffer_delete(GTK_TEXT_BUFFER(equation), &start, &end); + + /* Get new iterator position after deletion */ + gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(equation), &start, offset); + len = g_unichar_to_utf8(mp_serializer_get_radix(equation->priv->serializer), buffer); + buffer[len] = '\0'; + gtk_text_buffer_insert(GTK_TEXT_BUFFER(equation), &start, buffer, -1); + + in_radix = TRUE; + /* No need to adjust offset since we're replacing one char with one char */ + } else if (c == mp_serializer_get_thousands_separator(equation->priv->serializer)) { /* Didn't expect thousands separator - delete it */ if (!expect_tsep && in_number) { @@ -809,6 +828,9 @@ math_equation_get_equation(MathEquation *equation) /* Substitute radix character */ else if (c == mp_serializer_get_radix(equation->priv->serializer) && (last_is_digit || next_is_digit)) g_string_append_unichar(eq_text, '.'); + /* Support comma as decimal separator (French convention) */ + else if (c == ',' && last_is_digit && next_is_digit) + g_string_append_unichar(eq_text, '.'); else g_string_append_unichar(eq_text, c); |
