tag:blogger.com,1999:blog-6850721864152845156.post6537963700785763461..comments2015-05-31T19:35:58.482-05:00Comments on make_it; break_it; fix_it; change_it;: Engineering Notation in VBA/VB6j8g8jhttp://www.blogger.com/profile/07789626355050163893noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-6850721864152845156.post-65966835091797480312014-08-04T12:58:33.048-05:002014-08-04T12:58:33.048-05:00Thanks! This is nice. I would point out a typo in ...Thanks! This is nice. I would point out a typo in the excel format you posted, should be ##0.0E+0. But I ran into the same issue a while back.<br /><br />Not sure if it's actually shorter, but I had done this with a Mod function. I wrote my own Mod (or you could overload the operator) so it could deal with decimals and the output was always positive as with the Worksheet function MOD(). The pseudocode is as follows:<br />MyMod (As Double) = Log10(Abs(value)) Mod 3<br />MyMod value from [0 to 1) means there is only 1 digit before the decimal (vba format code "0.0##E+0")<br />from [1 to 2) means you want 2 digits before the decimal (vba format code "00.0#E+0")<br />from [2 to 3) means you want 3 digits before the decimal (vba format code "000.0E+0")<br /><br />In my case, I didn't need to deal with zero, and log10(val) = log(val)/log(10).<br />You can also leverage this to make all your engineering units have fixed precision as I showed here, which is nice.<br /><br />Cheers,<br />ScottAnonymousnoreply@blogger.com