Q:

"dir"-Input RTL but with LTR measurement data | "فثسف 3 cm فثسف" should be (فثسفy 3 cm فثسف)

Do someone know if this is an issue of the browser, the windows language or something in general?
I installed on my computer a second language called "Arabic (Saudi Arabia) Arabic (101) keyboard".

And if I enter a text like "test 3cm test" (for "3cm" I switch to German keyboard) its more or less correct. - with dir="rtl".

When I'm using ltr as dir it looks like when I'm copy&pasting it here.
فثسف 3cm فثسف
And now the (main) question.
When I add a space between 3 and cm it will be vice versa.

Do you know if it's possible to handle it with JavaScript or HTML like my picture modification below?

Or is it a language behaviour?
Thanks in Advance! :-)
What did I tried?

Using auto in dir

<html dir="rtl" lang="ar">
<body>
  <input type="text" dir="auto" style="text-align: left;" value="فثسف 3 cm فثسف" />
</body>
</html>

And this.

<html dir="rtl" lang="ar">
<body>
  <input type="text" dir="auto" style="text-align: right;" value="فثسف 3 cm فثسف" />
</body>
</html>

The value comes from this workflow.

Switch to Arabic (RTL language)
Write "test "
Switch to German (LTR language)
Write "3 cm "
Switch to Arabic (RTL language)
Write "test"
Strg + A in the Input and put it into value="STRG + V"

A:

I used @alex-cohn idea with &lrm; and &rlm; tags and developed something what I need 

var ltrMarkThere = false;
document.getElementById("test").addEventListener("keydown", function testKey(e) {
  if(e.key.match(/[0-9]/)) {
    document.getElementById("test").value += "\u202a";
    ltrMarkThere = true;
  } else if(ltrMarkThere && e.key.charCodeAt(0) > 127) {
    document.getElementById("test").value = document.getElementById("test").value.replace(/( ?)$/, "\u202c$1");
    ltrMarkThere = false;
  }
});
<html dir="rtl" lang="ar">
  <head>
  </head>
  <body>
    <input id="test" type="text" style="direction: rtl; text-align: right;" autocomplete="off" autofocus="true" value="فثسف ‪3 cm‬ فثسف" />
    <!-- There is a hidden UTF8 Right-to-left-mark and hidden UTF8 Left-to-right-mark which allows to have it like this  -->
  </body>
</html>

