How to drop a trailing zero (in mql5) like Excel?

 

How can I drop a trailing zero from a text string (in mql5) that will be written to a csv file. For example: "0.10" to "0.1" Basically, I want to save the mql5 to the csv in the same format that Excel exports to csv.

 
Richard:

How can I drop a trailing zero from a text string that will be written to a csv file. For example: "0.10" to "0.1"

Use the function StringSubstr()
 
Richard:

How can I drop a trailing zero from a text string that will be written to a csv file. For example: "0.10" to "0.1"

mt4 always remove 0 at back of every floating number if you use php to extact the data for processing use number_format function

[example]

if (strlen(substr(strrchr($value,"."), 1)) == 5) { $high = number_format($value,5); }

elseif (strlen(substr(strrchr($value,"."), 1)) == 4) { $high = number_format($value,4); }

elseif (strlen(substr(strrchr($value,"."), 1)) == 3) { $high = number_format($value,3); }

 
Ehsan Tarakemeh:
Use the function StringSubstr()

I've tried that, but a string like "0" is also deleted.

 
MUSTAFIZUL ALLIF BIN HAJI ABDUL LATIB:

mt4 always remove 0 at back of every floating number if you use php to extact the data for processing use number_format function

[example]

if (strlen(substr(strrchr($value,"."), 1)) == 5) { $high = number_format($value,5); }

elseif (strlen(substr(strrchr($value,"."), 1)) == 4) { $high = number_format($value,4); }

elseif (strlen(substr(strrchr($value,"."), 1)) == 3) { $high = number_format($value,3); }

I apologize, I should have mentioned this is mql5. StringSubstr also completely removes "0". Thank you for your help.

 
Richard:

I've tried that, but a string like "0" is also deleted.

For special cases use if-statements.
Or you can check if there's a "."  substring then remove the trailing zeroes. 

Use the following link to learn more about String functions:
https://www.mql5.com/en/docs/strings
 
Richard: For example: "0.10" to "0.1"
  1. Why do you care?
  2. Convert your number to a string. While the last digit is zero, reduce the length. Return the substring. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help
 
Ehsan Tarakemeh:
For special cases use if-statements.
Or you can check if there's a "0."  substring then remove the trailing zero. 

Use the following link to learn more about String functions:
https://www.mql5.com/en/docs/strings

I've already search the documentation. Nothing explains how to export to csv the same way as Excel. Thank you for your ideas.

 
Thank you to all who tried to help. I'll work it out myself.
 
William Roeder:
  1. Why do you care?
  2. Convert your number to a string. While the last digit is zero, reduce the length. Return the substring. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help

1. Why do I care? Because I don't want a bad csv file that crashes python with pandas code. Excel does it automatically, but I don't want to import every mt5 exported csv file into Excel and then have Excel export it correctly.

2. I have already done that. As I mentioned, it does not work if the only character is "0" (I don't want that one dropped). I've been reading the documentation and have not found the answer to my specific problem. I've also tried the various code page options but without avail.

Finally, I have no problem posting my code here, but as you said, "No free help." I'll do it myself.


P.S. Years ago, these forums were full of people trying to help each other. Those were the days.

To anyone else that actually tried to help, a sincere thank you.

 
Richard:

1. Why do I care? Because I don't want a bad csv file that crashes python with pandas code. Excel does it automatically, but I don't want to import every mt5 exported csv file into Excel and then have Excel export it correctly.

2. I have already done that. As I mentioned, it does not work if the only character is "0" (I don't want that one dropped). I've been reading the documentation and have not found the answer to my specific problem. I've also tried the various code page options but without avail.

Finally, I have no problem posting my code here, but as you said, "No free help." I'll do it myself.


P.S. Years ago, these forums were full of people trying to help each other. Those were the days.

To anyone else that actually tried to help, a sincere thank you.

You got help but you didn't listen. Stop criticising people trying to help you and start to be open minded.

Who have you ever helped here ?

It's a false issue, there is absolutely no need to remove this 0, it doesn't make sense.

Reason: