Android Question Hebrew Currency with Number String

EvgenyB4A

Active Member
Licensed User
I need to output the string like שח 10.00 where שח will be at the start and then 10.00. I can't succeed in anyway.
 

emexes

Well-Known Member
Licensed User
B4X:
Dim IOU As Double = 10.15    'money values better as Double (Float is only 6 digits accurate)
Dim MoneyString As String = "שח " & NumberFormat2(IOU, 1, 2, 2, False)
Log("How about " & MoneyString & " ?")

IOU = IOU * 2
MoneyString = Chr(8362) & " " & NumberFormat2(IOU, 1, 2, 2, False)
Log("Or do you prefer " & MoneyString & " ??")
 
Last edited:

EvgenyB4A

Active Member
Licensed User
Anyway I get the following: "How about שח 10.15 ?" I need that שח will be the first and then 10.15
 

emexes

Well-Known Member
Licensed User
Yeah, I just tested the second sample Chr(8362) and noticed that the first sample was still the wrong way around. That's interesting. I remember with Arabic writing in Windows, text used to move itself about when changing direction, perhaps the same is happening here when the text output routine sees your currency symbol.

update: the B4A IDE cursor does very strange things when traversing those characters too...
 

EvgenyB4A

Active Member
Licensed User
It is not because of currency symbol. If English part of string will be like "abcd" al will loos OK : " שח abcd" .
 

emexes

Well-Known Member
Licensed User
According to this page:

https://www.fileformat.info/info/unicode/char/5E9/index.htm

the first character is right-to-left, and I expect the other character will be too. So now I am looking at how to override text directionality. Or to trick it somehow into putting the symbol first.

A workaround might be to put the currency symbol in one label, and the monetary number in a separate label.
 

Mahares

Well Known Member
Licensed User
B4X:
Dim IOU As Double = 10.15   
    Dim s As String=NumberFormat2(IOU, 1, 2, 2, False)
    Log($"nw ${s}"$)    'displays: nw 10.15
 

emexes

Well-Known Member
Licensed User
I am going to have to admit defeat on this one, for tonight at least.

If you place text between the currency characters, then they stay in left-to-right order. So I figure if I could just find some non-printing characters to put between the currency characters, that would do the job (although no doubt I'd cop an ear-bashing from Erel ;-)

However, that doesn't work. Java's handling of text direction is irritatingly thorough.

I tried CSBuilder too, thinking that the formatting codes in that might interrupt the text direction handling, but... no luck there either.
 

emexes

Well-Known Member
Licensed User
Or apparently CSBuilder can include images within a string, so... you could include an IMAGE of the two currency characters... bit of an icky solution, but hey: if it works, it works ;-)
 

Mahares

Well Known Member
Licensed User
Or apparently CSBuilder can include images within a string, so... you could include an IMAGE of the two currency characters... bit of an icky solution, but hey: if it works, it works ;-)
Use string literals, you will get it:
B4X:
Dim IOU As Double = 10.15  
    Log($"nw ${NumberFormat2(IOU, 1, 2, 2, False)}"$)  'displays: nw 10.15
 

emexes

Well-Known Member
Licensed User
Give this a burl:
B4X:
Dim IOU As Double = 10.15    'money values better as Double (Float is only 6 digits accurate)
Dim MoneyString As String = Chr(0x200F) & NumberFormat2(IOU, 1, 2, 2, False) & " " & Chr(1513) & Chr(1495)
Log("How about " & MoneyString & " ?")

IOU = IOU * 2
MoneyString = Chr(8362) & " " & NumberFormat2(IOU, 1, 2, 2, False)
Log("Or do you prefer " & MoneyString & " ??")
 
Last edited:

emexes

Well-Known Member
Licensed User
It works. Chr(0x200F) makes a job.
I wish I could explain why it works, except that I'm a bit hazy about it myself.

Likewise, I wish I could say that I derived the solution by skill and wisdom, but in fact it was more by perseverance and luck.

I googled Unicode left right direction and eventually I found pages like http://unicode.org/reports/tr9/#Explicit_Directional_Embeddings

and from there I tried using various directional formatting characters and sequences until I found one that worked with both Log() and with Label.Text =
 
Top