Bool to String

 

Can we do like this?

bool takeprofit = TRUE;
Print(booltostring(takeprofit));


Output should be :

TRUE
 
anuj71:

Can we do like this?


Output should be :

why don't you just try it...

 
Paul Anscombe #:

why don't you just try it...

I tried and not working. That is the reason behind i am asking here. Is it possible to convert bool to string?
 
anuj71 #:
I tried and not working. That is the reason behind i am asking here. Is it possible to convert bool to string?
string result = flag ? "true" : "false";
 
Documentation on MQL5: Language Basics / Data Types
Documentation on MQL5: Language Basics / Data Types
  • www.mql5.com
Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
anuj71 #: I tried and not working. That is the reason behind i am asking here. Is it possible to convert bool to string?

Did the compiler not throw and error for your code? It should have!

Please learn to reference the online Book and Documentation

bool   bTakeProfit = true;                 // it is "true" and not "TRUE"
string sTakeProfit = (string) bTakeProfit; // explicit typecasting to a string

// The following will all output "true" ...
   Print(          bTakeProfit ); // Method 1 ... implicit typecasting 
   Print( (string) bTakeProfit ); // Method 2 ... explicit typecasting to a string
   Print(          sTakeProfit ); // Method 3 ... variable is already a string
MQL5 programming for traders - MetaTrader 5 algorithmic/automatic trading language manual
MQL5 programming for traders - MetaTrader 5 algorithmic/automatic trading language manual
  • www.mql5.com
MQL5 programming for traders - MetaTrader 5 algorithmic/automatic trading language manual
 
string result = (string) flag; // simplified - explicit typecasting to a string
 
anuj71 #:
I tried and not working. That is the reason behind i am asking here. Is it possible to convert bool to string?
 bool my_var = true;
  Print("my_var: " + my_var);    


 
Fernando Carreiro #:
Did the compiler not throw and error for your code? It should have!

Error : 'booltostring' - function not defined    output.mq4    31    7


Paul Anscombe #:


For me, it giving values like 0 and 1. 0 For false and 1 for True. 


Fernando Carreiro #:
string result = (string) flag; // simplified - explicit typecasting to a string


bool takeprofit = FALSE;    
Comment(
        "\n ::  bool     :", takeprofit,
        "\n ::  Bool string    :", (string) takeprofit,
        "\n ::  -------------------------------"
    );

Both returning values 0 not "FALSE". 

 
anuj71 #:

Error : 'booltostring' - function not defined    output.mq4    31    7


For me, it giving values like 0 and 1. 0 For false and 1 for True. 



Both returning values 0 not "FALSE". 

read the answers carefully. was already said that is 'true' not 'TRUE'.

 
Samuel Manoel De Souza #:

read the answers carefully. was already said that is 'true' not 'TRUE'.

bool takeprofit = true;    
Comment(
        "\n ::  bool     :", takeprofit,
        "\n ::  Bool string    :", (string) takeprofit,
        "\n ::  -------------------------------"
    );
This still return value 1 instead of word/string "true"