45
45
#include < unicode/listformatter.h>
46
46
#include < unicode/rbnf.h>
47
47
48
+ #include < numeric>
49
+
48
50
#include " qof.h"
49
51
#include " gnc-prefs.h"
50
52
#include " Account.h"
@@ -1498,26 +1500,33 @@ gnc_wrap_text_with_bidi_ltr_isolate (const char* text)
1498
1500
********************************************************************/
1499
1501
1500
1502
static std::string
1501
- number_to_words (double val)
1503
+ number_to_words (double val, int64_t denom )
1502
1504
{
1503
1505
UErrorCode status{U_ZERO_ERROR};
1504
1506
icu::RuleBasedNumberFormat formatter{icu::URBNF_SPELLOUT, icu::Locale{}, status};
1505
1507
icu::UnicodeString result;
1506
1508
std::string words;
1509
+ double int_part;
1507
1510
if (U_FAILURE (status))
1508
1511
{
1509
1512
PERR (" Error creating formatter: %s" , u_errorName (status));
1510
1513
return " " ;
1511
1514
}
1512
1515
1513
- formatter.format (std::fabs (val), result, status);
1516
+ const int frac_part = std::round (std::modf (std::fabs (val), &int_part) * denom);
1517
+ const std::vector<std::string> tail =
1518
+ { " " , _ (" and" ), " " , std::to_string (frac_part), " /" , std::to_string (denom) };
1519
+
1520
+ formatter.format (int_part, result, status);
1514
1521
if (U_FAILURE (status))
1515
1522
{
1516
1523
PERR (" Error formatting number: %s" , u_errorName (status));
1517
1524
return " " ;
1518
1525
}
1519
1526
1520
1527
result.toUTF8String (words);
1528
+
1529
+ words = std::accumulate (tail.begin (), tail.end (), words);
1521
1530
DEBUG (" Number %f in words: %s" , val, words.c_str ());
1522
1531
1523
1532
return words;
@@ -1534,7 +1543,7 @@ static double round(double x)
1534
1543
char *
1535
1544
numeric_to_words (gnc_numeric val)
1536
1545
{
1537
- return g_strdup (number_to_words (gnc_numeric_to_double (val)).c_str ());
1546
+ return g_strdup (number_to_words (gnc_numeric_to_double (val), gnc_numeric_denom (val) ).c_str ());
1538
1547
}
1539
1548
1540
1549
const char *
0 commit comments