diff --git a/c_glib/arrow-glib/decimal.cpp b/c_glib/arrow-glib/decimal.cpp index 04787aba47c89..9c0cf03607a84 100644 --- a/c_glib/arrow-glib/decimal.cpp +++ b/c_glib/arrow-glib/decimal.cpp @@ -202,6 +202,21 @@ garrow_decimal128_negate(GArrowDecimal128 *decimal) arrow_decimal->Negate(); } +/** + * garrow_decimal128_to_integer: + * @decimal: A #GArrowDecimal128. + * + * Returns: The 64-bit integer representation of the decimal. + * + * Since: 0.10.0 + */ +gint64 +garrow_decimal128_to_integer(GArrowDecimal128 *decimal) +{ + auto arrow_decimal = garrow_decimal128_get_raw(decimal); + return static_cast(*arrow_decimal); +} + G_END_DECLS GArrowDecimal128 * diff --git a/c_glib/arrow-glib/decimal.h b/c_glib/arrow-glib/decimal.h index 90cb247bc9e6f..ba9e18df2bf33 100644 --- a/c_glib/arrow-glib/decimal.h +++ b/c_glib/arrow-glib/decimal.h @@ -42,5 +42,6 @@ gchar *garrow_decimal128_to_string_scale(GArrowDecimal128 *decimal, gchar *garrow_decimal128_to_string(GArrowDecimal128 *decimal); void garrow_decimal128_abs(GArrowDecimal128 *decimal); void garrow_decimal128_negate(GArrowDecimal128 *decimal); +gint64 garrow_decimal128_to_integer(GArrowDecimal128 *decimal); G_END_DECLS diff --git a/c_glib/test/test-decimal.rb b/c_glib/test/test-decimal.rb index 03e88cfc3cb80..2528883233b9b 100644 --- a/c_glib/test/test-decimal.rb +++ b/c_glib/test/test-decimal.rb @@ -46,4 +46,10 @@ def test_negate decimal.negate assert_equal(positive_value, decimal.to_s) end + + def test_to_integer + integer_data = 999999999999999999 + decimal = Arrow::Decimal128.new(integer_data) + assert_equal(integer_data, decimal.to_i) + end end