January 13, 200521 yr Hi everyone, I have a calculation field that has text and numbers in it. It is basically a conversion field. The user enters one value in the "Qty Convert" field and then chooses the unit in the "from" field and the unit in the "to" field. The calc field displays something like: 100 Kilograms = 3527.396198 Ounces My problem is that I have to make the calc a text field not a number field so I can't format the number to include the thousand separator. I have a fairly long calculation to do this but is there an easier way? I would also like to add a million separator in the unlikely event that it is needed. Any help is greatly appreciated
January 13, 200521 yr Use four fields: a number field (for the original quantity, formatted with the thousands separator), a text field for the From units, a text field for the To units, and a number field for the result (formatted with the thousands separator).
January 13, 200521 yr Author Thanks for replying so quickly, I tried that but then I have a spacing problem. Although it is just Aesthetic it is annoying. I have to make the number fields big enough to accomodate 7 places on both sides of the decimal point and the slide left doesn't help. Is there another way to make it more continuous?
January 13, 200521 yr There was a discussion of this recently here. Check Ugo Di Luca's first post. HTH, Jerry
January 14, 200521 yr Author Thank you guys this is great I used Di Luca's Calc and it worked great. But just to cause touble is there a way to eliminate the unused zeros? I want to be able to have 7 digits past the decimal but only when they are needed. Thanks again
January 14, 200521 yr Try substituting the last portion of the calc (starting with "Choose( Precision = 0") with Let( P = Min( Precision; Length(Substitute( GetAsNumber( "." & Right( Number; Length(Number) - Position( Number & Case( not PatternCount( Number; "." ); "." ); "."; 0; 1 ) )); "."; "" )) ); Choose( P = 0 ; "." & Right( 10 ^ P & Abs( Round( Number ; P ) ) * ( 10 ^ P ) ; P )) )
January 14, 200521 yr Perhaps it can be shorter? Instead of the original ... Choose( PRECISION = 0 , ... use ... Choose( (PRECISION <= 0) or not Mod( Number , 1 ) , ...
January 14, 200521 yr Right. I was thinking that Mod might return screwy results here, but I guess that was Int I was remembering. In that case, ditch the above suggestion and go with Let( P = Min( Precision; Length(Mod( Number; 1 )) - 1 ); Choose( P = 0; "." & Right( 10 ^ P & Abs( Round( Number ; P ) ) * ( 10 ^ P ) ; P )) )
January 14, 200521 yr Author Those work great for anything 7 decimal places and less. But anything with more rounds off and leaves the 7 zeros. I can't thank you guys enough for your time, I really appreciate it.
January 14, 200521 yr I still don't get it. This, IMHO, is all the modification required: Choose( (PRECISION <= 0) [color:"red"] or not Mod( NUMBER , 1 ) , "." & Right( 10^PRECISION & Abs( Round( NUMBER , PRECISION ) ) * ( 10^PRECISION ) , PRECISION ))
January 14, 200521 yr Okay, this one seems to work well. Let([ M = Mod( Number; 1 ); P = Min( Precision; Length(Round( M; Precision )) - 1 ) ]; Choose( P <= 0; "." & Right( 10 ^ P & Abs( Round( Number; P ) ) * ( 10 ^ P ) ; P )) )
January 14, 200521 yr Oh. Sorry, I completely misunderstood. I thought he wanted to cut off the trailing zeroes in case the number was an integer. P.S. I still think it should be P <= 0.
January 14, 200521 yr I couldn't figure out why until I entered some negative precisions. Without it, the decimal point appears at the end of an integer. Good call. I modified the calc above to include it. I also broke negative Number values. It's fixed now.
January 15, 200521 yr Here's another variant (you're not the only one bored): Choose ( Precision <= 0 ; "." & Middle ( Abs ( Mod ( Round ( Number ; Precision ) ; 1 ) ) ; 2 ; Precision + 1 ) )
January 15, 200521 yr or even simpler: Choose ( not Mod ( Number ; 1 ) ; Abs ( Mod ( Round ( Number ; Precision ) ; 1 ) ) )
Create an account or sign in to comment