Properties
Category
English
Similar Topics
Statistics
Comments
18
Participants
5
Subscribers
6
Votes
1
Views
119
Share
Decimals in text.
Answered
I'm doing an activity for money, so I'd like to force two decimals even if it's an integer. I've tried in the text box settings and the whole applet. I've tried adding .001 to the variable as well.
Ideas or insights? Thanks for any help!
Files:
LZMoney.ggb
 GeoGebra
 Help
 Partners

Contact us
 Feedback & Questions
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 +43 677 6137 2693
© 2017 International GeoGebra Institute
perhaps
text1 = If[IsDefined[IndexOf[".", "$"b]], Take["$" b "0", 1, IndexOf[".", "$"b] + 2], "$" b ".00"]
or larger
text2 = If[IsDefined[IndexOf[".", "$" round(b, 2)]], Take["$" round(b, 2) "0", 1, IndexOf[".", "$" round(b, 2)] + 2], "$" round(b, 2) ".00"]
I tested it without problem
.
Take["$" (num + 0.0001), 1, IndexOf[".", "$" (num + 0.0001)] + 2]
so you can use any rounding option for another numbers (ie: interest)
In my first solution you must set rounding local for text1.
In the solution of mathmagic you must set rounding global in Menu/Option.
.
Here a solution is independent from roundingoptions (and also OK for num < 0)
.
"$ "
+ (If[sgn(num) < 0, "", ""])
+ (First["" + (abs(round(num 100))), Length["" + (abs(round(num 100)))]  2])
+ "." + (Last["" + (abs(round(num 100))), 2])
.
(above in one line)
No. you can use the rounding you want.
saludos
@mathmagic
In my environment GGB 5.0.366 Win10
I must set Menu/option/rounding to 4
Ok
it is possible I have 5 decimals by default.
a question: If I select for a text 5 decimals in local properties of the text, how I return the text to global selection?
It seems the local rounding (properties/text/rounding) has no effect for this command. Maybe this is a a bug.
the effect is lost for indexof[] command, perhaps the decimal affects only at final showed text
my question continues without answer
Silly that I didn't think of text commands.
Now I'm going crazy! Rami's solution worked perfectly, except when num=0 it gave me ?.?. So I added a textbox to show $0.00 when money = 0 and now the same text that worked before only gives ?.? Later: now it's working again, except for the 0 case. I don't know what changed!
Here's the current: https://www.geogebra.org/m/bNwhCNFb
And I'll attach one with both versions of the solution. ¡Mil gracias, mi GGB gente! I was being grateful for your help, and my spouse asked if either of you were on Twitter or in the #mtbos. Are you? (I'm @mathhombre there.)
I hope this version works in all cases,
exept infinity (example: 0/1)
.
.text1 = "$ "
+ (If[sgn(money) < 0, "", ""])
+ (First["" + (If[abs(round(money 100)) < 100, "0", ""]) + (abs(round(money 100))), Max[1, Length["" + (abs(round(money 100)))]  2]])
+ "."
+ (Last["00" + (abs(round(money 100))), 2])
.
all in one line
For some applications the second expression (sign) is optional
.
I hope somebody else create a version more short/clear in one line and independent of rounding parameter.
this is better:
.
text1 = "$ "
+ (If[sgn(money) < 0, "", ""])
+ ("" + (floor(abs(round(money 100) / 100))))
+ "."
+ (Last["00" + (abs(round(money 100))), 2])
.
perhaps
text1 = If[IsDefined[IndexOf[".", "$"b]], Take["$" b "0", 1, IndexOf[".", "$"b] + 2], "$" b ".00"]
or larger
text2 = If[IsDefined[IndexOf[".", "$" round(b, 2)]], Take["$" round(b, 2) "0", 1, IndexOf[".", "$" round(b, 2)] + 2], "$" round(b, 2) ".00"]
I tested it without problem
a=123.4567
If[a ≟ 0, "0." + (Sum[Sequence["0", i, 1, 2]]), If[a < 0, "",""] + (UnicodeToText[Reverse[Insert[TextToUnicode["."], Reverse[TextToUnicode[If[Length["" round(abs(a) 10², 0)] ≤ 2, Sum[Sequence["0", i, 1, abs(2  Length["" round(abs(a) 10², 0)] )+ 1] ] ,""]+ "" round(abs(a) 10², 0)]], 2+1]]])]
A late entry to the contest :)
Great !!
Additional comment: need in Properties/Text/Rounding = 2 (or something else)
suppose you have a tabletext in algebra view. then you drag and drop the text from algebra view to graphics
a new text is created
is this the desirable behavior?
Comments have been locked on this page!