I'm looking for a way to set the decimal places for text i'm outputting by counting the decimal places of another variable.
Im thinking I could count the length of the input, and figure out how many decimals it is, then set the format of the output based on that. But I'm not 100% sure how...
Maybe something like:
I feel like there has got to be a better way than what I'm thinking above...
I just need to set decimal places of strTextOut to be the same as my input.
Ex:
If my input is 50.125:
I want strTxtOut format to be set to ".000"
Or if my input is 50.12
I want the format for strTxtOut to be set to ".00"
Or if my input is 0.5625
I want the format for strTxtOut to be ".0000"
Anyone know how best to do this?
Im thinking I could count the length of the input, and figure out how many decimals it is, then set the format of the output based on that. But I'm not 100% sure how...
Maybe something like:
Code:
intInLen = Len(dblTextIn) <--length of input number
intInDec = InStr(dblTextIn,".") <--location where first decimal occurs
intDec = intInLen - intInDec <--how many decimal places I need
strTextOut= Format(dblTextOut, ".000"[<--zeros based on intDec])<--but how??
I feel like there has got to be a better way than what I'm thinking above...
I just need to set decimal places of strTextOut to be the same as my input.
Ex:
If my input is 50.125:
I want strTxtOut format to be set to ".000"
Or if my input is 50.12
I want the format for strTxtOut to be set to ".00"
Or if my input is 0.5625
I want the format for strTxtOut to be ".0000"
Anyone know how best to do this?