1if (typeof T === 'undefined') require('../setup'); 2 3T('toPrecision', function () { 4 5 function t(expected, n, sd, rm) { 6 T.assertEqual(expected, new Decimal(n).toPrecision(sd, rm)); 7 } 8 9 function tx(fn, msg) { 10 T.assertException(fn, msg); 11 } 12 13 Decimal.config({ 14 precision: 20, 15 rounding: 4, 16 toExpNeg: -7, 17 toExpPos: 40, 18 minE: -9e15, 19 maxE: 9e15 20 }); 21 22 // ---------------------------------------------------------------- v8 start 23 24 t('1e+27', '1.2345e+27', 1); 25 t('1.2e+27', '1.2345e+27', 2); 26 t('1.23e+27', '1.2345e+27', 3); 27 t('1.235e+27', '1.2345e+27', 4); 28 t('1.2345e+27', '1.2345e+27', 5); 29 t('1.23450e+27', '1.2345e+27', 6); 30 t('1.234500e+27', '1.2345e+27', 7); 31 32 t('-1e+27', '-1.2345e+27', 1); 33 t('-1.2e+27', '-1.2345e+27', 2); 34 t('-1.23e+27', '-1.2345e+27', 3); 35 t('-1.235e+27', '-1.2345e+27', 4); 36 t('-1.2345e+27', '-1.2345e+27', 5); 37 t('-1.23450e+27', '-1.2345e+27', 6); 38 t('-1.234500e+27', '-1.2345e+27', 7); 39 40 t('7', 7, 1); 41 t('7.0', 7, 2); 42 t('7.00', 7, 3); 43 44 t('-7', -7, 1); 45 t('-7.0', -7, 2); 46 t('-7.00', -7, 3); 47 48 t('9e+1', 91, 1); 49 t('91', 91, 2); 50 t('91.0', 91, 3); 51 t('91.00', 91, 4); 52 53 t('-9e+1', -91, 1); 54 t('-91', -91, 2); 55 t('-91.0', -91, 3); 56 t('-91.00', -91, 4); 57 58 t('9e+1', 91.1234, 1); 59 t('91', 91.1234, 2); 60 t('91.1', 91.1234, 3); 61 t('91.12', 91.1234, 4); 62 t('91.123', 91.1234, 5); 63 t('91.1234', 91.1234, 6); 64 t('91.12340', 91.1234, 7); 65 t('91.123400', 91.1234, 8); 66 t('-9e+1', -91.1234, 1); 67 t('-91', -91.1234, 2); 68 t('-91.1', -91.1234, 3); 69 t('-91.12', -91.1234, 4); 70 t('-91.123', -91.1234, 5); 71 t('-91.1234', -91.1234, 6); 72 t('-91.12340', -91.1234, 7); 73 t('-91.123400', -91.1234, 8); 74 75 t('NaN', NaN, 1); 76 t('Infinity', Infinity, 2); 77 t('-Infinity', -Infinity, 2); 78 79 t('5.55000000000000e-7', 0.000000555, 15); 80 t('-5.55000000000000e-7', -0.000000555, 15); 81 t('-1.2e-9', -.0000000012345, 2); 82 t('-1.2e-8', -.000000012345, 2); 83 t('-1.2e-7', -.00000012345, 2); 84 t('1e+8', 123456789, 1); 85 t('123456789', 123456789, 9); 86 t('1.2345679e+8', 123456789, 8); 87 t('1.234568e+8', 123456789, 7); 88 t('-1.234568e+8', -123456789, 7); 89 90 t('-0.0000012', -.0000012345, 2); 91 t('-0.000012', -.000012345, 2); 92 t('-0.00012', -.00012345, 2); 93 t('-0.0012', -.0012345, 2); 94 t('-0.012', -.012345, 2); 95 t('-0.12', -.12345, 2); 96 t('-1.2', -1.2345, 2); 97 t('-12', -12.345, 2); 98 t('-1.2e+2', -123.45, 2); 99 t('-1.2e+3', -1234.5, 2); 100 t('-1.2e+4', -12345, 2); 101 t('-1.235e+4', -12345.67, 4); 102 t('-1.234e+4', -12344.67, 4); 103 104 t('1.3', 1.25, 2); 105 t('1.4', 1.35, 2); 106 107 Decimal.rounding = 0; 108 109 t('1e+4', 9631.01, 1, 4); 110 t('1.0e+7', 9950095.87, 2, 4); 111 t('1e+1', '9.856839969', 1, 4); 112 t('1e+2', '97.504', 1, 4); 113 t('1e+5', 97802.6, 1, 4); 114 t('1e+1', 9.9617, 1, 4); 115 t('1e+3', 989.2, 1, 4); 116 t('1.0e+5', 99576, 2, 4); 117 t('1e+8', '96236483.87', 1, 4); 118 119 // ------------------------------------------------------------------ v8 end 120 121 t('-0.00001', '-0.00001', 1); 122 t('-0.000090000000', '-0.00009', 8); 123 t('-7e-7', '-0.0000007', 1); 124 t('68.9316834061848', '68.931683406184761912218250317', 15); 125 t('7.8601018089704732e+27', '7860101808970473167417935916.60087069', 17); 126 t('3.21445885399803244067719798337437062000000e-11', '0.0000000000321445885399803244067719798337437062', 42); 127 t('-8171786349835057630612358814.162756978', '-8171786349835057630612358814.162756977984', 37); 128 t('3340.9039701', '3340.903970019817086594869184429527413533291595472085', 11); 129 t('-7269097658095414435895.9161181115739745427300313060', '-7269097658095414435895.916118111573974542730031306', 50); 130 t('0.00000632207', '0.00000632206077863', 6); 131 t('6e+2', '573', 1); 132 t('7.4e-7', '0.000000738', 2); 133 t('-5.031561e-7', '-0.0000005031560306227217140253964236911907612837', 7); 134 t('-4.291e+11', '-429050053964', 4); 135 t('8.514e+7', '85131637', 4); 136 t('-3.4e-9', '-0.000000003326783057540398442677461', 2); 137 t('6.9404295962722512e-20', '0.00000000000000000006940429596272251146200868514973032594273', 17); 138 t('-828376248340605120247.15155295014', '-828376248340605120247.15155295013990774586360178257303370779', 32); 139 t('-7.9828e+6', '-7982750.6677764682946015520272838914918899297118139169410659', 5); 140 t('0.00712610393722542527880200', '0.007126103937225425278801997738', 24); 141 t('-5.7e+4', '-56242', 2); 142 t('-8928855203945443164.755136735230293537', '-8928855203945443164.755136735230293536124112124', 37); 143 t('5218572327.99', '5218572327.98424443372003772604597054153304', 12); 144 t('71707870535238750871516796339.60', '71707870535238750871516796339.59678962573869890935', 31); 145 t('88817462.7137982220652429', '88817462.71379822206524285939115943006583441400005007918', 24); 146 t('3.00000e-9', '0.000000003', 6); 147 t('-6.053', '-6.05291095813493573191', 4); 148 t('6.51630828677e+19', '65163082867698740076', 12); 149 t('2483202135696501.60187899', '2483202135696501.60187898870193199949004966876115645', 24); 150 t('1.0766e-10', '0.000000000107650515680635692286894826641576642261', 5); 151 t('642724503819056076.659397077514269963295025', '642724503819056076.659397077514269963295024012414', 42); 152 t('-7.1192e+21', '-7119169102619893823635.32141854354', 5); 153 t('-6.717481255640638829101946114674e-8', '-0.000000067174812556406388291019461146732616998258', 31); 154 t('-12.41976452', '-12.4197645179995365323309894', 10); 155 t('-6.529258780126449116249954644017839921024112900e-16', '-0.00000000000000065292587801264491162499546440178399210241129', 46); 156 t('-441838.0', '-441838', 7); 157 t('1.128285293592950e-8', '0.000000011282852935929493101783925259749957192', 16); 158 t('-8.654857e+7', '-86548567', 7); 159 t('3.8883293855303995e-7', '0.00000038883293855303994672627854769926811949', 17); 160 t('3.25870000e-13', '0.00000000000032587', 9); 161 t('3.702e+6', '3701031.59037494113', 4); 162 t('-3580077435.93682917449675702508371047', '-3580077435.93682917449675702508371046631533', 36); 163 t('-7.400', '-7.4', 4); 164 t('109519523263844229810.068', '109519523263844229810.067657779734413280795410968892638', 24); 165 t('-509247322311590671954830.86847660619', '-509247322311590671954830.8684766061855', 35); 166 t('7.5518638430980800496570562671727890e-10', '0.00000000075518638430980800496570562671727889997', 35); 167 t('-5056721600639122835615986051.468831942818200', '-5056721600639122835615986051.4688319428182', 43); 168 t('-1.796146861125551785886171829251460000000000e-16', '-0.000000000000000179614686112555178588617182925146', 43); 169 t('6.0e+2', '599', 2); 170 t('7.619930e-16', '0.00000000000000076199293', 7); 171 t('834668.2370121038159610193', '834668.237012103815961019258574789273273342', 25); 172 t('-3.92251395952329649490768e+26', '-392251395952329649490767912.240768552138247705202732', 24); 173 t('-47504099413385554632166.5098', '-47504099413385554632166.50972492550706', 27); 174 175 Decimal.rounding = 1; 176 177 t('-1.4e+9', '-1336106841', 2, 0); 178 t('-2244450.2134814273335263', '-2244450.2134814273335262397290334104071203538487453309626146', 23, 0); 179 t('8.74e+29', '873625255363763952428129881990.679929486040461455296118489', 3, 0); 180 t('-1.85453549733179613185923288786', '-1.8545354973317961318592328878502252820666161607740183', 30, 0); 181 t('431.7150651927', '431.71506519265522010949747887049', 13, 0); 182 t('-8606297211156287.52520023752564', '-8606297211156287.5252002375256362382564355963505470716151', 30, 0); 183 t('-8.4634889709e+24', '-8463488970828351722405003.220603', 11, 0); 184 185 t('-844789036.5239726', '-844789036.52397268892', 16); 186 t('-5056.20629012767878749185273209679064306054', '-5056.206290127678787491852732096790643060542', 42); 187 t('-0.3287519131314873763501859870298952500', '-0.32875191313148737635018598702989525', 37); 188 t('-60729764', '-60729764', 8); 189 t('-7.622e-14', '-0.00000000000007622481594531380999826456196664586', 4); 190 t('-4686402261639729535.736324492474', '-4686402261639729535.7363244924747488', 31); 191 t('-2.0', '-2', 2); 192 t('-13801188035233586637950193108.13592574381473451125649500', '-13801188035233586637950193108.135925743814734511256495', 55); 193 t('0.0000807327587149839799300000', '0.00008073275871498397993', 24); 194 t('-6.000000e-8', '-0.00000006', 7); 195 t('-3.83574993e+11', '-383574993535', 9); 196 t('7.6987000000000000e-14', '0.000000000000076987', 17); 197 t('80928866804.6112050947427973', '80928866804.6112050947427973864826014844575374353', 27); 198 t('-0.00730140', '-0.0073014067221009206110062377503733', 6); 199 t('2.72104773884160491036088486e+30', '2721047738841604910360884862459.4086993273252009015', 27); 200 t('3.008780781917733594e+25', '30087807819177335941398228.1424107931203', 19); 201 t('-1.31528920779613669158250146972297797867760000000000000000000e-19', '-0.00000000000000000013152892077961366915825014697229779786776', 60); 202 t('-8.5e+11', '-858982311008.257025719798657844609315293821', 2); 203 t('-3.6312e-12', '-0.0000000000036312827608449878', 5); 204 t('-0.0060000', '-0.006', 5); 205 t('-4.65727e+23', '-465727983501322687372765', 6); 206 t('-0.00000332331666628036603', '-0.000003323316666280366035430077076052', 18); 207 t('3.533702e-8', '0.00000003533702791135712510338001418872124', 7); 208 t('-0.04340', '-0.0434', 4); 209 t('-597340.278566069086858587852236235470', '-597340.2785660690868585878522362354706741', 36); 210 t('6.000e-8', '0.00000006', 4); 211 t('-3.624323359112776296e-19', '-0.00000000000000000036243233591127762966338166', 19); 212 t('-3731378568692042924197.154', '-3731378568692042924197.15400334142251496795634388', 25); 213 t('-68249040894032065692.62', '-68249040894032065692.62771690318493', 22); 214 t('8786096722661914.89732851', '8786096722661914.89732851188880184891692993684242690315', 24); 215 t('-1.8413321536281347264486372900000000000e-12', '-0.00000000000184133215362813472644863729', 38); 216 t('4.0e-9', '0.0000000040395827543504045', 2); 217 t('-2.9427e+16', '-29427119846374896', 5); 218 t('-917760614.4', '-917760614.45404359204911454', 10); 219 t('8e+4', '89427', 1); 220 t('0.00000920323988134356953828667260', '0.0000092032398813435695382866726', 27); 221 t('8.2e+16', '82068995955708118', 2); 222 t('3.35195944828e+26', '335195944828445911672446409.3379497158141', 12); 223 t('-3.89774891030e-9', '-0.00000000389774891030223957363124620581272897758735065471', 12); 224 t('-4', '-4', 1); 225 t('8', '8', 1); 226 t('1.41172955693912934219137966000000e-10', '0.000000000141172955693912934219137966', 33); 227 t('9.21481e+13', '92148111958857', 6); 228 t('-5.859975978432853e-18', '-0.0000000000000000058599759784328539', 16); 229 t('-72.0', '-72', 3); 230 t('3785098751297.8929911950994079707157472', '3785098751297.89299119509940797071574729867819252140059', 38); 231 t('4.38e+16', '43893416753778361.297703358127215475077814', 3); 232 t('-33110.29096', '-33110.2909623520267070846514', 10); 233 t('-74.38305251784882707720486436292121914036495', '-74.3830525178488270772048643629212191403649548392158614', 43); 234 235 Decimal.rounding = 2; 236 237 t('5.80e+18', '5805164734299168659.6173113885173384955443', 3, 1); 238 t('-1.719875889271327', '-1.719875889271327133154458155573493605566221534', 16, 1); 239 t('113.672129563', '113.672129563441659725876055771857758675550104070419635029', 12, 1); 240 t('-77950052814622081084397.9', '-77950052814622081084397.91853869253589242574', 24, 1); 241 t('4.53106985e+27', '4531069852787151785292512309.2901993579425172826443679877', 9, 1); 242 t('45285.246089613169416440797840714', '45285.2460896131694164407978407142422013937', 32, 1); 243 t('307760226411464.7333268079863299', '307760226411464.73332680798632996332324381779707', 31, 1); 244 245 t('-0.0300', '-0.0300921721159558', 3); 246 t('65317841202.20949859371772273480125', '65317841202.2094985937177227348012464402154', 34); 247 t('-8.9231575495202e+29', '-892315754952021994731329589682.1894180393920044085713', 14); 248 t('-2.8075679202e-8', '-0.0000000280756792028583066', 11); 249 t('9.71456e+9', '9714558552', 6); 250 t('2.9514099281e-10', '0.00000000029514099281', 11); 251 t('-1.24459e+14', '-124459985101107', 6); 252 t('0.0000734657394154607815562372000000', '0.0000734657394154607815562372', 30); 253 t('1.78719530353972e+15', '1787195303539715', 15); 254 t('-2.8e+9', '-2861102528', 2); 255 t('-8.74480375581000e-9', '-0.00000000874480375581', 15); 256 t('-1792404726015427380.248150830448457643618022', '-1792404726015427380.248150830448457643618022', 43); 257 t('-678437320202616518.2220157912209286', '-678437320202616518.22201579122092864', 34); 258 t('-1.937304915215780220809799809655893674619672771e-8', '-0.000000019373049152157802208097998096558936746196727718', 46); 259 t('824172.15863347130174103087', '824172.15863347130174103086069960571', 26); 260 t('1.90040714061724000e-9', '0.00000000190040714061724', 18); 261 t('-1634488249956745498.58311', '-1634488249956745498.58311123049258868631623840423306', 24); 262 t('0.0000019600923098540334001755857361187871270117098000', '0.0000019600923098540334001755857361187871270117098', 47); 263 t('8.383e+4', '83829', 4); 264 t('2.843306120337864064e+23', '284330612033786406376718', 19); 265 t('1.86235e+15', '1862340943682995.08270612464203237562317928642459', 6); 266 t('-2.31e+13', '-23195312138083', 3); 267 t('5.450237e+21', '5450236028274773541895.65198933808968167192289601277', 7); 268 t('-0.008976419749408075453861117865459', '-0.00897641974940807545386111786545972434475187220274239581167', 31); 269 t('-761181660548661030.25', '-761181660548661030.25539542029', 20); 270 t('-1844205.93619958', '-1844205.936199580689273072905714475263817', 15); 271 t('4842.77906784902805070438222238898372327093', '4842.77906784902805070438222238898372327092242428134814721', 42); 272 t('-4.161198953445629503503971e+26', '-416119895344562950350397179', 25); 273 t('1.084e+4', '10836', 4); 274 t('8.71081704218174598654542083000e-8', '0.0000000871081704218174598654542083', 30); 275 t('7.9139683e+36', '7913968291641940848703040206324645237.8515176490912667096', 8); 276 t('-0.000008', '-0.000008', 1); 277 t('8.3660085625e+34', '83660085624983922907621996804192921.3992927', 11); 278 t('0.000006980263008', '0.000006980263007423150706324065130475391', 10); 279 t('-31348084528321454060964445534333629317.69561497283830023', '-31348084528321454060964445534333629317.69561497283830023', 55); 280 t('-2417953792643886.3485495754363678888681996409674308643', '-2417953792643886.3485495754363678888681996409674308643', 53); 281 t('4.0e+6', '3982592', 2); 282 t('-2092315.015029722200', '-2092315.0150297222', 19); 283 t('-364992136844916.9092238', '-364992136844916.909223894931280218350055327754935', 22); 284 t('8.34e+24', '8333642861002789136219873', 3); 285 t('7.6008837179413e+14', '760088371794122.3380234188299740029832128019574765416', 14); 286 t('-6655726127.0', '-6655726127', 11); 287 288 Decimal.rounding = 3; 289 290 t('-1.7218673528e+29', '-172186735288586033321621121024.11240623', 11, 2); 291 t('-3.31e+28', '-33197729862068219255677464974', 3, 2); 292 t('-4.835191326e+29', '-483519132605694848658321267839.23575134378118945659616358', 10, 2); 293 t('7.3', '7.24882150443803', 2, 2); 294 t('-89186640077683569.407061427673', '-89186640077683569.4070614276736450982125609', 29, 2); 295 t('-49379651041268.5', '-49379651041268.548293', 15, 2); 296 t('-7685054.17489171951660', '-7685054.17489171951660508194254495141726065698575306365447451', 21, 2); 297 298 t('-39449414270333.925852213835', '-39449414270333.925852213834759031494508489474', 26); 299 t('-7.50437989976', '-7.50437989975503711836768', 12); 300 t('-0.000004303975760000000', '-0.00000430397576', 16); 301 t('-16040233916257241895.97650633973989', '-16040233916257241895.9765063397398857', 34); 302 t('-7438.9287248601393819', '-7438.9287248601393818639176907606', 20); 303 t('9.857465584298e-7', '0.000000985746558429876825600458537705318327799', 13); 304 t('532637.9095983547284850466577958315920', '532637.90959835472848504665779583159203905641996', 37); 305 t('-1.40416695292e+30', '-1404166952915258058306475434520.7856110230505157', 12); 306 t('60346876.6670832429026869255506808488', '60346876.6670832429026869255506808488', 36); 307 t('-2.52466133e+23', '-252466132238128405832984', 9); 308 t('55', '55', 2); 309 t('-63075151.962465776516325792253177939493172', '-63075151.9624657765163257922531779394931714', 41); 310 t('7.411461e+17', '741146113404361548.543142388', 7); 311 t('-58835755359067474972692072494278983.7', '-58835755359067474972692072494278983.6314961114191480012916', 36); 312 t('-333', '-333', 3); 313 t('7.24707e+13', '72470760481059', 6); 314 t('39232618.1513515442233995765535454389', '39232618.151351544223399576553545438981252', 36); 315 t('-4e+5', '-357994', 1); 316 t('-1.90e+4', '-18904.11335233460016293296574557643545512393801643609213933', 3); 317 t('-6585152111956929.924309477123328984876184272828762900', '-6585152111956929.9243094771233289848761842728287629', 52); 318 t('4.505e-7', '0.0000004505328', 4); 319 t('-2.4125965461846e+19', '-24125965461845662271', 14); 320 t('4.82673137e+33', '4826731373891127996812671510065700.871947701', 9); 321 t('-6621278.2', '-6621278.1120573461544975284970826524341806671316100080257485', 8); 322 t('-1.8015392869565386634525164264799463344376205007391000000e-7', '-0.00000018015392869565386634525164264799463344376205007391', 56); 323 t('-0.00026465463574439280006655492609887593', '-0.00026465463574439280006655492609887592672292239588307259', 35); 324 t('4.87815228988300090', '4.8781522898830009076096556452567', 18); 325 t('-5.1107117199524082779077801201617e+35', '-511071171995240827790778012016163902', 32); 326 t('1.4734242515706890557e+20', '147342425157068905574.390834406', 20); 327 t('-4019325091848890817268596991.815200', '-4019325091848890817268596991.8152', 34); 328 t('3.8e+14', '384715413967421', 2); 329 t('7483444.49', '7483444.498791364040133403947480439118040376737700653', 9); 330 t('-594538312.6255', '-594538312.625485172379', 13); 331 t('0.00753000', '0.00753', 6); 332 t('8.1440148247e+13', '81440148247675.27449603492606125135884', 11); 333 t('8.444003009300e+21', '8444003009300239495556', 13); 334 t('2308.1529840912558574923966042774800185916972327325289', '2308.1529840912558574923966042774800185916972327325289261', 53); 335 t('2.67e+3', '2674.698673623', 3); 336 t('-2.82819136180287470854625537e+30', '-2828191361802874708546255368471.80800005766', 27); 337 t('518250411', '518250411', 9); 338 t('3.2e+4', '32661.9135347256259375001777960775509', 2); 339 t('29.15347602216416991973', '29.153476022164169919735054013077734177', 22); 340 t('-4.611285536613066108e+30', '-4611285536613066107912600830385', 19); 341 t('-51774110.0705144989023975360207167071143094356321', '-51774110.070514498902397536020716707114309435632036586', 48); 342 t('-11969053.91', '-11969053.9052', 10); 343 344 Decimal.rounding = 4; 345 346 t('687378946204028.408158998985701', '687378946204028.408158998985701430935094', 30, 3); 347 t('42.452', '42.4523909443358871476552683504968536100051', 5, 3); 348 t('-22771061110217019663705702.44170142085172', '-22771061110217019663705702.44170142085171219649140996', 40, 3); 349 t('-1470.640309974016167512235698629586', '-1470.6403099740161675122356986295857257144815364', 34, 3); 350 t('-1.110228e+27', '-1110227398804733429555663947.06619', 7, 3); 351 t('-6.4898237111e+26', '-648982371105405071851661301', 11, 3); 352 t('-4641197449469148.658850361201903', '-4641197449469148.658850361201902222', 31, 3); 353 354 t('7.905300379788e+16', '79053003797878062.6454954', 13); 355 t('-6.83490000000e-13', '-0.00000000000068349', 12); 356 t('-62760641815.69084973661201201', '-62760641815.690849736612012010742308663', 28); 357 t('0.000704', '0.000704496313', 3); 358 t('82926865286287.8852357368342860830310721063079299643', '82926865286287.88523573683428608303107210630792996432', 51); 359 t('-0.00032388272393900301214220090249', '-0.00032388272393900301214220090248744799603424908', 29); 360 t('8.6e+12', '8621641486938.4837308885005093571508566552428700982454', 2); 361 t('2', '2', 1); 362 t('1.4641440117052559075e+20', '146414401170525590746.047955203899370771105088', 20); 363 t('3511.925583', '3511.925583', 10); 364 t('2861824.253079699095728', '2861824.253079699095727765750377038689', 22); 365 t('-3.940097756e+10', '-39400977564.548924098664431671700066962', 10); 366 t('-888', '-888', 3); 367 t('-0.000302106125213724988141721256104', '-0.00030210612521372498814172125610432438685', 30); 368 t('6943.4804552555315615809650428503', '6943.480455255531561580965042850266831249032130818358478956', 32); 369 t('3365678', '3365678.3397481381125085749', 7); 370 t('-5.3943374314e+19', '-53943374313769567458.386865325', 11); 371 t('-6.67880509225510150542252852147049489938254298497979', '-6.6788050922551015054225285214704948993825429849797925563674', 51); 372 t('1.36424e+18', '1364240644139816224.60228356028', 6); 373 t('1.410236477950416725e+23', '141023647795041672538410.84935693266374259666015274447', 19); 374 t('-802.817765', '-802.81776500697712984253334522', 9); 375 t('-5.276210722424690668896260075355037218851', '-5.27621072242469066889626007535503721885096', 40); 376 t('-0.000874209568970788', '-0.0008742095689707877849902027926289294748756775668387', 15); 377 t('0.092053833162002', '0.09205383316200189249855864903410820435666385119723209239', 14); 378 t('7.0656298318128209e-14', '0.0000000000000706562983181282092835675843980510112', 17); 379 t('-8.66511516852116659e+18', '-8665115168521166587', 18); 380 t('3.3490648464e+22', '33490648463534229842937.79268276945692333064632966129475', 11); 381 t('-39041587174692569176.82740706154183894', '-39041587174692569176.827407061541838942655371389185', 37); 382 t('-3834.0', '-3834', 5); 383 t('-0.008912382644814418776268630', '-0.00891238264481441877626863', 25); 384 t('-2.1e+5', '-206119', 2); 385 t('4.83340000000e-8', '0.000000048334', 12); 386 t('3.185196533675230520000000000000e-19', '0.000000000000000000318519653367523052', 31); 387 t('6.0431217298488095562718496137220939447806000000000000000e-17', '0.000000000000000060431217298488095562718496137220939447806', 56); 388 389 Decimal.rounding = 5; 390 391 t('-8e+26', '-786589693451258754942279859.3834', 1, 4); 392 t('-26.0', '-26', 3, 4); 393 t('-8.462226728e+11', '-846222672789.2087639320702375427266333530942524245', 10, 4); 394 t('-4e-7', '-0.0000004019666978288041783154210868', 1, 4); 395 t('-315609.775843992', '-315609.775843992', 15, 4); 396 t('-3.319e+9', '-3318880945', 4, 4); 397 t('-6', '-6.2847', 1, 4); 398 399 t('-1408003897645960.648499616456', '-1408003897645960.648499616456', 28); 400 t('-1.0', '-1', 2); 401 t('-8.28e+14', '-827860423543649', 3); 402 t('0.00054398953021585321711560388890', '0.00054398953021585321711560388889590290139888', 29); 403 t('-4.409e-9', '-0.000000004408792', 4); 404 t('4.0000e-10', '0.0000000004', 5); 405 t('3.40e+16', '34001779327925905', 3); 406 t('-9.03e+34', '-90332622851356543193546536340366547', 3); 407 t('-4.5320e+16', '-45320100856429143.39155209710530673318222777', 5); 408 t('3.618e+30', '3618328715720583671291544414202', 4); 409 t('-1003.61140', '-1003.61139687804673322250551', 9); 410 t('-8139415035028632370.38737', '-8139415035028632370.38736602659835', 24); 411 t('8e+7', '83198058', 1); 412 t('-7.99492e+14', '-799491603856548', 6); 413 t('444', '444', 3); 414 t('0.00000613258266938', '0.0000061325826693823067791292255878336353793864046451956723', 12); 415 t('-554696279951718746537611.26040', '-554696279951718746537611.26040029508470430208572833137315', 29); 416 t('446', '446.189185820662709163412845035853873', 3); 417 t('22873128187827109553471831451.06623850867', '22873128187827109553471831451.06623850866672688842662473', 40); 418 t('9e+5', '880389', 1); 419 t('-6.7516118890844e+16', '-67516118890844443.625641', 14); 420 t('-0.36107158435820', '-0.36107158435820101656696353075596201902674001080619510849', 14); 421 t('8.958386374640407365', '8.958386374640407364828679985365339921820421370157246', 19); 422 t('3e+2', '257', 1); 423 t('-1.904659739878e+18', '-1904659739878060478.113131137688927604413210083841', 13); 424 t('-0.0000627142', '-0.00006271421732891589577305487292334', 6); 425 t('3.310541e+8', '331054103', 7); 426 t('-1.793886e+23', '-179388600781592577147651.2641684828762234473', 7); 427 t('0.0004600', '0.00046', 4); 428 t('-2.9e+21', '-2906505321975413509885', 2); 429 t('86415.94739506', '86415.9473950557683374', 13); 430 t('6.730414', '6.7304135909152', 7); 431 t('-5.032367e+14', '-503236749968584', 7); 432 t('-5.0241682013868216287718e+32', '-502416820138682162877178622610283', 23); 433 t('-0.0552606118984074172116684879479087', '-0.0552606118984074172116684879479087', 33); 434 t('91017414629852252476380368766.471', '91017414629852252476380368766.47117955844005', 32); 435 t('28586.32124747000', '28586.32124747000107561236523943', 16); 436 t('0.000001935665545322534195131', '0.0000019356655453225341951305040536808235510260170838860718', 22); 437 t('7.8', '7.803563246406851025', 2); 438 t('-4.89914223627882382434323e+26', '-489914223627882382434323457.50920109688497974624541155867073', 24); 439 t('384718796891211107', '384718796891211107', 18); 440 t('42510.74002309897971230194', '42510.7400230989797123019438399853496258', 25); 441 t('-7.388e+11', '-738804895894', 4); 442 t('-5.0000000e-7', '-0.0000005', 8); 443 444 Decimal.rounding = 6; 445 446 t('42334337596496149636254', '42334337596496149636254.4926162509306406461', 23, 5); 447 t('-7e+9', '-7246374971.34279698356', 1, 5); 448 t('71516263932998764871838469072', '71516263932998764871838469072.280115355524', 29, 5); 449 t('71257489.5995227415169007618702182092', '71257489.59952274151690076187021820922744', 36, 5); 450 t('268492835', '268492834.77041', 9, 5); 451 t('50325.551277778107847798802', '50325.551277778107847798801525', 26, 5); 452 t('-5.289303987e+29', '-528930398665449048343281311623.69686', 10, 5); 453 454 t('0.08000', '0.08', 4); 455 t('-4.5132e+21', '-4513243388120382069815.8508153058993058875', 5); 456 t('-73549', '-73549.2594630551663822238', 5); 457 t('1.275868004728922895890883e+29', '127586800472892289589088296800.6', 25); 458 t('-0.0003715444034899460421534099962225699000', '-0.0003715444034899460421534099962225699', 37); 459 t('-6.9625565265e+24', '-6962556526511822306135536', 11); 460 t('1.67583703641e+13', '16758370364138.915293525076269061228714877', 12); 461 t('-173594.95064085553515176707313947534918109631092170', '-173594.950640855535151767073139475349181096310921699', 50); 462 t('-6.9503965525e+19', '-69503965525000308384.151383', 11); 463 t('4.411225e+20', '441122486054080817112', 7); 464 t('2.467044064783596937642371770e+31', '24670440647835969376423717700462.39', 28); 465 t('3.9711897549481645654e+24', '3971189754948164565361634.8039734590476326224193520402091769', 20); 466 t('-1.4757613208690e+21', '-1475761320868963235919.64499841336073105746686372924161', 14); 467 t('91683083887068.6191146', '91683083887068.61911461351134520171343337804061135', 21); 468 t('-7923074181102822.578', '-7923074181102822.5778', 19); 469 t('-6.800e-8', '-0.000000068', 4); 470 t('-2.57954671081460000000e-10', '-0.00000000025795467108146', 21); 471 t('5.5352911972e-9', '0.000000005535291197169667611325365189624523452', 11); 472 t('6.0488358e+8', '604883577', 8); 473 t('-7.575535014e-9', '-0.00000000757553501363609536678641245355', 10); 474 t('7.547067960578900230644488e-10', '0.00000000075470679605789002306444877998602723', 25); 475 t('-3.64561456763e+12', '-3645614567625.4', 12); 476 t('9.0e-7', '0.0000009', 2); 477 t('7e+2', '687', 1); 478 t('517277827334839.8174848543680868', '517277827334839.8174848543680868015165926618', 31); 479 t('7e+2', '655.46270361324473194', 1); 480 t('1632131488313153.49737424823493573157', '1632131488313153.497374248234935731568', 36); 481 t('274068317992.5998880719845028748169734442', '274068317992.5998880719845028748169734442394151076', 40); 482 t('-7.060e-9', '-0.00000000706025531009734073', 4); 483 t('0.004444', '0.0044439457493', 4); 484 t('72482770689153111154104782082.023', '72482770689153111154104782082.022764082943227214833851', 32); 485 t('5.9130694036072794206e+24', '5913069403607279420613864.152', 20); 486 t('843384561300245347961437.966', '843384561300245347961437.96592523791', 27); 487 t('0.0000035198821282510000000', '0.000003519882128251', 20); 488 t('-1.00371560130267706870097e-9', '-0.00000000100371560130267706870096885251', 24); 489 t('17504218.4970302', '17504218.49703016415913667026121376499', 15); 490 t('-5e-9', '-0.000000005169058703', 1); 491 t('6.922803246e+10', '69228032455', 10); 492 t('-16', '-16', 2); 493 t('-1.355147513468192707127939151e+40', '-13551475134681927071279391508441439066206.58705380600075', 28); 494 t('81670324.1197758695', '81670324.1197758695212865075629796973196504241126', 18); 495 t('0.00005', '0.00004797485174640366805332660647', 1); 496 t('-4.864397594e-10', '-0.0000000004864397594461335282648538530108953965681345', 10); 497 t('47694105.2312532', '47694105.23125322528167211284521303', 15); 498 t('-4.962106181e+26', '-496210618135432953927871636.779236', 10); 499 t('1.2800030559497062236642e+37', '12800030559497062236641930592334626609.7332', 23); 500 t('-574830783.7', '-574830783.6689168903917696583746514637433390929', 10); 501 t('5969.431086199057470', '5969.43108619905746956015212970904111744101', 19); 502 t('-4.8e+3', '-4814.32904953003285', 2); 503 t('4.297e+16', '42973001760252134', 4); 504 t('-5.7628e+6', '-5762846.590152347665179652381407653797146356303622218259885', 5); 505 t('904864662232032.160612401810317927291657403142932', '904864662232032.16061240181031792729165740314293194205879163', 48); 506 t('7.9892e+20', '798923115068265241915.537619430376605', 5); 507 t('-8.97759349384000643', '-8.97759349384000643427096282979', 18); 508 509 t('123.45', '12.345e1'); 510 511 tx(function () {new Decimal(1.23).toPrecision('3')}, "(1.23).toPrecision('3')"); 512 tx(function () {new Decimal(1.23).toPrecision(new Decimal(3))}, "(1.23).toPrecision(new Decimal(3))"); 513 tx(function () {new Decimal(1.23).toPrecision(null)}, "(1.23).toPrecision(null)"); 514 tx(function () {new Decimal(1.23).toPrecision(NaN)}, "(1.23).toPrecision(NaN)"); 515 tx(function () {new Decimal(1.23).toPrecision('NaN')}, "(1.23).toPrecision('NaN')"); 516 tx(function () {new Decimal(1.23).toPrecision([])}, "(1.23).toPrecision([])"); 517 tx(function () {new Decimal(1.23).toPrecision({})}, "(1.23).toPrecision({})"); 518 tx(function () {new Decimal(1.23).toPrecision('')}, "(1.23).toPrecision('')"); 519 tx(function () {new Decimal(1.23).toPrecision(' ')}, "(1.23).toPrecision(' ')"); 520 tx(function () {new Decimal(1.23).toPrecision('hello')}, "(1.23).toPrecision('hello')"); 521 tx(function () {new Decimal(1.23).toPrecision('\t')}, "(1.23).toPrecision('\t')"); 522 tx(function () {new Decimal(1.23).toPrecision(new Date)}, "(1.23).toPrecision(new Date)"); 523 tx(function () {new Decimal(1.23).toPrecision(new RegExp)}, "(1.23).toPrecision(new RegExp)"); 524 tx(function () {new Decimal(1.23).toPrecision(2.01)}, "(1.23).toPrecision(2.01)"); 525 tx(function () {new Decimal(1.23).toPrecision(10.5)}, "(1.23).toPrecision(10.5)"); 526 tx(function () {new Decimal(1.23).toPrecision('1.1e1')}, "(1.23).toPrecision('1.1e1')"); 527 tx(function () {new Decimal(1.23).toPrecision(true)}, "(1.23).toPrecision(true)"); 528 tx(function () {new Decimal(1.23).toPrecision(false)}, "(1.23).toPrecision(false)"); 529 tx(function () {new Decimal(1.23).toPrecision(function (){})}, "(1.23).toPrecision(function (){})"); 530 tx(function () {new Decimal(1.23).toPrecision('-1')}, ".toPrecision('-1')"); 531 tx(function () {new Decimal(1.23).toPrecision(-23)}, ".toPrecision(-23)"); 532 tx(function () {new Decimal(1.23).toPrecision(1e9 + 1)}, ".toPrecision(1e9 + 1)"); 533 tx(function () {new Decimal(1.23).toPrecision(0)}, ".toPrecision(0)"); 534 tx(function () {new Decimal(1.23).toPrecision('-0')}, ".toPrecision('-0')"); 535 tx(function () {new Decimal(1.23).toPrecision(0.9)}, ".toPrecision(0.9)"); 536 tx(function () {new Decimal(1.23).toPrecision('-1e-1')}, ".toPrecision('-1e-1')"); 537 tx(function () {new Decimal(1.23).toPrecision(Infinity)}, ".toPrecision(Infinity)"); 538 tx(function () {new Decimal(1.23).toPrecision('-Infinity')}, ".toPrecision('-Infinity')"); 539 540 tx(function () {new Decimal(1.23).toPrecision(1, '3')}, "(1.23).toPrecision('3')"); 541 tx(function () {new Decimal(1.23).toPrecision(1, new Decimal(3))}, "(1.23).toPrecision(new Decimal(3))"); 542 tx(function () {new Decimal(1.23).toPrecision(1, null)}, "(1.23).toPrecision(null)"); 543 tx(function () {new Decimal(1.23).toPrecision(1, NaN)}, "(1.23).toPrecision(1, NaN)"); 544 tx(function () {new Decimal(1.23).toPrecision(1, 'NaN')}, "(1.23).toPrecision(1, 'NaN')"); 545 tx(function () {new Decimal(1.23).toPrecision(1, [])}, "(1.23).toPrecision(1, [])"); 546 tx(function () {new Decimal(1.23).toPrecision(1, {})}, "(1.23).toPrecision(1, {})"); 547 tx(function () {new Decimal(1.23).toPrecision(1, '')}, "(1.23).toPrecision(1, '')"); 548 tx(function () {new Decimal(1.23).toPrecision(1, ' ')}, "(1.23).toPrecision(1, ' ')"); 549 tx(function () {new Decimal(1.23).toPrecision(1, 'hello')}, "(1.23).toPrecision(1, 'hello')"); 550 tx(function () {new Decimal(1.23).toPrecision(1, '\t')}, "(1.23).toPrecision(1, '\t')"); 551 tx(function () {new Decimal(1.23).toPrecision(1, new Date)}, "(1.23).toPrecision(1, new Date)"); 552 tx(function () {new Decimal(1.23).toPrecision(1, new RegExp)}, "(1.23).toPrecision(1, new RegExp)"); 553 tx(function () {new Decimal(1.23).toPrecision(1, 2.01)}, "(1.23).toPrecision(1, 2.01)"); 554 tx(function () {new Decimal(1.23).toPrecision(1, 10.5)}, "(1.23).toPrecision(1, 10.5)"); 555 tx(function () {new Decimal(1.23).toPrecision(1, '1.1e1')}, "(1.23).toPrecision(1, '1.1e1')"); 556 tx(function () {new Decimal(1.23).toPrecision(1, true)}, "(1.23).toPrecision(1, true)"); 557 tx(function () {new Decimal(1.23).toPrecision(1, false)}, "(1.23).toPrecision(1, false)"); 558 tx(function () {new Decimal(1.23).toPrecision(1, function (){})}, "(1.23).toPrecision(1, function (){})"); 559 tx(function () {new Decimal(1.23).toPrecision(1, '-1')}, ".toPrecision(1, '-1')"); 560 tx(function () {new Decimal(1.23).toPrecision(1, -23)}, ".toPrecision(1, -23)"); 561 tx(function () {new Decimal(1.23).toPrecision(1, 9)}, ".toPrecision(1, 8)"); 562 tx(function () {new Decimal(1.23).toPrecision(1, '-0')}, ".toPrecision(1, '-0')"); 563 tx(function () {new Decimal(1.23).toPrecision(1, 0.9)}, ".toPrecision(1, 0.9)"); 564 tx(function () {new Decimal(1.23).toPrecision(1, '-1e-1')}, ".toPrecision(1, '-1e-1')"); 565 tx(function () {new Decimal(1.23).toPrecision(1, Infinity)}, ".toPrecision(1, Infinity)"); 566 tx(function () {new Decimal(1.23).toPrecision(1, '-Infinity')}, ".toPrecision(1, '-Infinity')"); 567}); 568