Slobey Posted January 13, 2005 Posted January 13, 2005 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
transpower Posted January 13, 2005 Posted January 13, 2005 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).
Slobey Posted January 13, 2005 Author Posted January 13, 2005 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?
QuinTech Posted January 13, 2005 Posted January 13, 2005 There was a discussion of this recently here. Check Ugo Di Luca's first post. HTH, Jerry
Slobey Posted January 14, 2005 Author Posted January 14, 2005 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
-Queue- Posted January 14, 2005 Posted January 14, 2005 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 )) )
comment Posted January 14, 2005 Posted January 14, 2005 Perhaps it can be shorter? Instead of the original ... Choose( PRECISION = 0 , ... use ... Choose( (PRECISION <= 0) or not Mod( Number , 1 ) , ...
-Queue- Posted January 14, 2005 Posted January 14, 2005 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 )) )
Slobey Posted January 14, 2005 Author Posted January 14, 2005 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.
comment Posted January 14, 2005 Posted January 14, 2005 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 ))
-Queue- Posted January 14, 2005 Posted January 14, 2005 He doesn't want the trailing zeroes, which is why I used a dynamic precision.
-Queue- Posted January 14, 2005 Posted January 14, 2005 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 )) )
comment Posted January 14, 2005 Posted January 14, 2005 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.
-Queue- Posted January 14, 2005 Posted January 14, 2005 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.
comment Posted January 15, 2005 Posted January 15, 2005 Here's another variant (you're not the only one bored): Choose ( Precision <= 0 ; "." & Middle ( Abs ( Mod ( Round ( Number ; Precision ) ; 1 ) ) ; 2 ; Precision + 1 ) )
comment Posted January 15, 2005 Posted January 15, 2005 or even simpler: Choose ( not Mod ( Number ; 1 ) ; Abs ( Mod ( Round ( Number ; Precision ) ; 1 ) ) )
-Queue- Posted January 17, 2005 Posted January 17, 2005 Excellent! I hate it when I make things too difficult.
Recommended Posts
This topic is 7319 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now