[ANSWERED] How to limit decimal output in Text Draw
-
-
The Javascript code of @DusX s post did not work for me, but Javascript would sure be the cleanest way. But the approach with the text formatter also works fine. Just paste following into it: P1:4.2 where 4 is how many number of digits are left of the decimal and 2 how many of digits right of the decimal.
Best Michel
-
thank you both, since I had the formatter already implemented, I followed that one and it works great.
However, someday I'll have a look at the Javascript. It looks quite simple and might be a good starting point for learning to implement Javascripts.
Is there somewhere else, where I could lookm up the formatting commands? Somewhere other than the Izzy manual, from where I could not really understand it (blame it on me).
Cheers
-
well I don't know were, but I usually use the infos inside Isadora (when hovering with the mouse). But I guess they are not different than the ones in the manual.
-
for me the problem with the javascript is that you don't get the 0 at the end of the decimal. You get 23 and not 23.00 or 23.1 and not 23.10.
The other problem I have is that you get with both (javascript and text formatter) a dot for decimal and not a comma as usual in Europe. Do you know a way to correct it.
thanks
Jean-François
-
Ok the code from @DusX does work, I just did not realise he put the Javascript into a user actor and therefore I did not change the input value to 2. I added the labelling of the inputs and output, this was added later to the Javascript actor. Well as far as I know JavaScript does not allow comma instead of a point. If you want that you have to convert the output to a string, but then you can't use it as number anymore. Even though Switzerland is in Europe we also use a point instead of a comma.
// iz_input 1 "float in" // iz_input 2 "num of decimals" // iz_output 1 "rnd val" function main() { function Nrnd(num, places){ return +(Math.round(num + "e+" + places) + "e-" + places); } R = Nrnd(arguments[0],arguments[1]); return R; }
-
Hi there!
Happy to help. You use the JavaScript method .toLocaleString() for this. Basically you give it an valid language like "en-US" and provide the number and the decimals that you prefer.
See the example file.
Forum Example - Formatted String based on Language
JavaScript docs page
https://www.w3schools.com/jsre...
Valid language parameters
ar-SA
Arabic (Saudi Arabia)bn-BD
Bangla (Bangladesh)bn-IN
Bangla (India)cs-CZ
Czech (Czech Republic)da-DK
Danish (Denmark)de-AT
Austrian Germande-CH
"Swiss" Germande-DE
Standard German (as spoken in Germany)el-GR
Modern Greeken-AU
Australian Englishen-CA
Canadian Englishen-GB
British Englishen-IE
Irish Englishen-IN
Indian Englishen-NZ
New Zealand Englishen-US
US Englishen-ZA
English (South Africa)es-AR
Argentine Spanishes-CL
Chilean Spanishes-CO
Colombian Spanishes-ES
Castilian Spanish (as spoken in Central-Northern Spain)es-MX
Mexican Spanishes-US
American Spanishfi-FI
Finnish (Finland)fr-BE
Belgian Frenchfr-CA
Canadian Frenchfr-CH
"Swiss" Frenchfr-FR
Standard French (especially in France)he-IL
Hebrew (Israel)hi-IN
Hindi (India)hu-HU
Hungarian (Hungary)id-ID
Indonesian (Indonesia)it-CH
"Swiss" Italianit-IT
Standard Italian (as spoken in Italy)ja-JP
Japanese (Japan)ko-KR
Korean (Republic of Korea)nl-BE
Belgian Dutchnl-NL
Standard Dutch (as spoken in The Netherlands)no-NO
Norwegian (Norway)pl-PL
Polish (Poland)pt-BR
Brazilian Portuguesept-PT
European Portuguese (as written and spoken in Portugal)ro-RO
Romanian (Romania)ru-RU
Russian (Russian Federation)sk-SK
Slovak (Slovakia)sv-SE
Swedish (Sweden)ta-IN
Indian Tamilta-LK
Sri Lankan Tamilth-TH
Thai (Thailand)tr-TR
Turkish (Turkey)zh-CN
Mainland China, simplified characterszh-HK
Hong Kong, traditional characterszh-TW
Taiwan, traditional characters
-
Also on the Add-on section now :)
-
-
@michel Thanks... did miss that this time. It has already helped me. I'm getting friends with the text formatter ;-)