From eb6e424fd59229e08e4e1995b631ace9472b8d35 Mon Sep 17 00:00:00 2001 From: Christoph Holtermann Date: Thu, 24 Mar 2022 09:43:34 +0100 Subject: [PATCH] another float value --- bindings/python/example_scripts/GncNumeric.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bindings/python/example_scripts/GncNumeric.py b/bindings/python/example_scripts/GncNumeric.py index 32700b856a..70b56a5591 100644 --- a/bindings/python/example_scripts/GncNumeric.py +++ b/bindings/python/example_scripts/GncNumeric.py @@ -40,6 +40,15 @@ print(n4, "==", g4, ":", n4 == g4) print('Same float with higher precision: %.32f' % n4) print() +# Create from float +n5 = 2245.67 +g5 = GncNumeric(n5) +print("5 - create from float") +print(n5, "(", type(n5), ") =>", g5) +print(n5, "==", g5, ":", n5 == g5) +print('Same float with higher precision: %.32f' % n5) +print() + # Compare float, string and int print("Compare GncNumeric from float (4) to GncNumeric from string (2)") print(g2, "==", g4, ":", g2 == g4) @@ -67,6 +76,18 @@ print() # Convert GncNumeric from float to remove errors print("Convert float to different denominator to remove conversion errors") -g5 = g4.convert(1000, GNC_HOW_RND_ROUND) -print(g4, "(", type(g4), ") =>", g5) +g4b = g4.convert(1000, GNC_HOW_RND_ROUND) +print(g4, "(", type(g4), ") =>", g4b) +print() + +# Create from float with specified significant figures +print(f"Create from float (Example 5, ={n5}) with specified significant figures") +for sigfigs in range(0,20): + print(sigfigs, GncNumeric(n5, GNC_DENOM_AUTO, GNC_HOW_DENOM_SIGFIGS(sigfigs))) +print() + +# Convert GncNumeric from float to remove errors +print("Convert float to different denominator to remove conversion errors") +g5b = g5.convert(1000, GNC_HOW_RND_ROUND) +print(g5, "(", type(g5), ") =>", g5b)